From f52003261f5f9dbba3eede3b6edbf61cbaf42ed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=81=8F=E5=8F=B3?= Date: Mon, 9 Mar 2020 16:04:51 +0800 Subject: [PATCH] :bug: Fix TextArea[autoSize] don't scroll bottom in Firefox (#22014) close #21870 --- components/input/ResizableTextArea.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/components/input/ResizableTextArea.tsx b/components/input/ResizableTextArea.tsx index 7d5186a261..a6b7677ab7 100644 --- a/components/input/ResizableTextArea.tsx +++ b/components/input/ResizableTextArea.tsx @@ -65,6 +65,7 @@ class ResizableTextArea extends React.Component { raf.cancel(this.resizeFrameId); this.resizeFrameId = raf(() => { this.setState({ resizing: false }); + this.fixFirefoxAutoScroll(); }); }); }; @@ -74,6 +75,21 @@ class ResizableTextArea extends React.Component { 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;