🐛 Typography editable should focus at the end (#21268)

close #21261
This commit is contained in:
偏右 2020-02-07 13:15:24 +08:00 committed by afc163
parent 88bed67368
commit eea0b028c9
2 changed files with 16 additions and 2 deletions

View File

@ -46,8 +46,11 @@ class Editable extends React.Component<EditableProps, EditableState> {
};
componentDidMount() {
if (this.textarea) {
this.textarea.focus();
if (this.textarea && this.textarea.resizableTextArea) {
const { textArea } = this.textarea.resizableTextArea;
textArea.focus();
const { length } = textArea.value;
textArea.setSelectionRange(length, length);
}
}

View File

@ -241,6 +241,17 @@ describe('Typography', () => {
wrapper.find('TextArea').simulate('blur');
});
});
it('should focus at the end of textarea', () => {
const wrapper = mount(<Paragraph editable>content</Paragraph>);
wrapper
.find('.ant-typography-edit')
.first()
.simulate('click');
const textareaNode = wrapper.find('textarea').getDOMNode();
expect(textareaNode.selectionStart).toBe(7);
expect(textareaNode.selectionEnd).toBe(7);
});
});
it('warning if use setContentRef', () => {