Browse Source

🐛 Fix TextArea[autoSize] don't scroll bottom in Firefox (#22014)

close #21870
pull/22422/head
偏右 5 years ago
committed by afc163
parent
commit
f52003261f
  1. 16
      components/input/ResizableTextArea.tsx

16
components/input/ResizableTextArea.tsx

@ -65,6 +65,7 @@ class ResizableTextArea extends React.Component<TextAreaProps, TextAreaState> {
raf.cancel(this.resizeFrameId);
this.resizeFrameId = raf(() => {
this.setState({ resizing: false });
this.fixFirefoxAutoScroll();
});
});
};
@ -74,6 +75,21 @@ class ResizableTextArea extends React.Component<TextAreaProps, TextAreaState> {
raf.cancel(this.resizeFrameId);
}
// https://github.com/ant-design/ant-design/issues/21870
fixFirefoxAutoScroll() {
try {
if (document.activeElement === this.textArea) {
const currentStart = this.textArea.selectionStart;
const currentEnd = this.textArea.selectionEnd;
this.textArea.setSelectionRange(currentStart, currentEnd);
}
} catch (e) {
// Fix error in Chrome:
// Failed to read the 'selectionStart' property from 'HTMLInputElement'
// http://stackoverflow.com/q/21177489/3040605
}
}
renderTextArea = () => {
const { prefixCls, autoSize, autosize, className, disabled } = this.props;
const { textareaStyles, resizing } = this.state;

Loading…
Cancel
Save