Browse Source

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

close #21261
pull/21289/head
偏右 5 years ago
committed by afc163
parent
commit
eea0b028c9
  1. 7
      components/typography/Editable.tsx
  2. 11
      components/typography/__tests__/index.test.js

7
components/typography/Editable.tsx

@ -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);
}
}

11
components/typography/__tests__/index.test.js

@ -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', () => {

Loading…
Cancel
Save