Skip to content

Commit 80ca9b0

Browse files
committed
fix: textarea scroll at firfox
1 parent 700427d commit 80ca9b0

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

components/descriptions/style/index.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
font-weight: normal;
4242
font-size: @font-size-base;
4343
line-height: @line-height-base;
44-
white-space: nowrap;
4544

4645
&::after {
4746
position: relative;

components/input/ResizableTextArea.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,24 @@ const ResizableTextArea = {
5555
raf.cancel(this.resizeFrameId);
5656
this.resizeFrameId = raf(() => {
5757
this.setState({ resizing: false });
58+
this.fixFirefoxAutoScroll();
5859
});
5960
});
6061
},
62+
// https://github.com/ant-design/ant-design/issues/21870
63+
fixFirefoxAutoScroll() {
64+
try {
65+
if (document.activeElement === this.$refs.textArea) {
66+
const currentStart = this.$refs.textArea.selectionStart;
67+
const currentEnd = this.$refs.textArea.selectionEnd;
68+
this.$refs.textArea.setSelectionRange(currentStart, currentEnd);
69+
}
70+
} catch (e) {
71+
// Fix error in Chrome:
72+
// Failed to read the 'selectionStart' property from 'HTMLInputElement'
73+
// http://stackoverflow.com/q/21177489/3040605
74+
}
75+
},
6176

6277
renderTextArea() {
6378
const props = getOptionProps(this);
@@ -89,7 +104,7 @@ const ResizableTextArea = {
89104
}
90105
const style = {
91106
...textareaStyles,
92-
...(resizing ? { overflow: 'hidden' } : null),
107+
...(resizing ? { overflowX: 'hidden', overflowY: 'hidden' } : null),
93108
};
94109
const textareaProps = {
95110
attrs: otherProps,

components/input/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ exports[`renders ./antdv-demo/docs/input/demo/addon.md correctly 1`] = `
1313
exports[`renders ./antdv-demo/docs/input/demo/allowClear.md correctly 1`] = `<div><span class="ant-input-affix-wrapper"><input placeholder="input with clear icon" type="text" class="ant-input"><span class="ant-input-suffix"></span></span> <br> <br> <span class="ant-input-affix-wrapper ant-input-affix-wrapper-textarea-with-clear-btn"><textarea placeholder="textarea with clear icon" class="ant-input"></textarea></span></div>`;
1414
1515
exports[`renders ./antdv-demo/docs/input/demo/autosize-textarea.md correctly 1`] = `
16-
<div><textarea placeholder="Autosize height based on content lines" class="ant-input" style="height: 0px; min-height: -9007199254740991px; max-height: 9007199254740991px; overflow: hidden;"></textarea>
17-
<div style="margin: 24px 0px;"></div> <textarea placeholder="Autosize height with minimum and maximum number of lines" class="ant-input" style="height: -24px; min-height: -8px; max-height: -24px; overflow: hidden;"></textarea>
18-
<div style="margin: 24px 0px;"></div> <textarea placeholder="Controlled autosize" class="ant-input" style="height: -20px; min-height: -12px; max-height: -20px; overflow: hidden;"></textarea></div>
16+
<div><textarea placeholder="Autosize height based on content lines" class="ant-input" style="height: 0px; min-height: -9007199254740991px; max-height: 9007199254740991px; overflow-y: hidden; overflow-x: hidden;"></textarea>
17+
<div style="margin: 24px 0px;"></div> <textarea placeholder="Autosize height with minimum and maximum number of lines" class="ant-input" style="height: -24px; min-height: -8px; max-height: -24px; overflow-y: hidden; overflow-x: hidden;"></textarea>
18+
<div style="margin: 24px 0px;"></div> <textarea placeholder="Controlled autosize" class="ant-input" style="height: -20px; min-height: -12px; max-height: -20px; overflow-y: hidden; overflow-x: hidden;"></textarea></div>
1919
`;
2020
2121
exports[`renders ./antdv-demo/docs/input/demo/basic.md correctly 1`] = `<input placeholder="Basic usage" type="text" class="ant-input">`;

0 commit comments

Comments
 (0)