Skip to content

Commit

Permalink
🐛 Typography editable should focus at the end
Browse files Browse the repository at this point in the history
close #21261
  • Loading branch information
afc163 committed Feb 7, 2020
1 parent d23c550 commit 9c7ec87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions components/typography/Editable.tsx
Expand Up @@ -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);
}
}

Expand Down
11 changes: 11 additions & 0 deletions components/typography/__tests__/index.test.js
Expand Up @@ -287,6 +287,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', () => {
Expand Down

0 comments on commit 9c7ec87

Please sign in to comment.