Skip to content

Commit 0b7481e

Browse files
committed
fix: textarea shake #2005 #1964
1 parent 3d3884b commit 0b7481e

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

components/input/ResizableTextArea.jsx

+29-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import inputProps from './inputProps';
99
import PropTypes from '../_util/vue-types';
1010
import { getOptionProps, getListeners } from '../_util/props-util';
1111

12+
const RESIZE_STATUS_NONE = 0;
13+
const RESIZE_STATUS_RESIZING = 1;
14+
const RESIZE_STATUS_RESIZED = 2;
15+
1216
const TextAreaProps = {
1317
...inputProps,
1418
autosize: PropTypes.oneOfType([Object, Boolean]),
@@ -20,7 +24,7 @@ const ResizableTextArea = {
2024
data() {
2125
return {
2226
textareaStyles: {},
23-
resizing: false,
27+
resizeStatus: RESIZE_STATUS_NONE,
2428
};
2529
},
2630
mixins: [BaseMixin],
@@ -39,6 +43,18 @@ const ResizableTextArea = {
3943
},
4044
},
4145
methods: {
46+
handleResize(size) {
47+
const { resizeStatus } = this.$data;
48+
const { autoSize } = this.$props;
49+
50+
if (resizeStatus !== RESIZE_STATUS_NONE) {
51+
return;
52+
}
53+
this.$emit('resize', size);
54+
if (autoSize) {
55+
this.resizeOnNextFrame();
56+
}
57+
},
4258
resizeOnNextFrame() {
4359
raf.cancel(this.nextFrameActionId);
4460
this.nextFrameActionId = raf(this.resizeTextarea);
@@ -51,11 +67,15 @@ const ResizableTextArea = {
5167
}
5268
const { minRows, maxRows } = autoSize;
5369
const textareaStyles = calculateNodeHeight(this.$refs.textArea, false, minRows, maxRows);
54-
this.setState({ textareaStyles, resizing: true }, () => {
70+
this.setState({ textareaStyles, resizeStatus: RESIZE_STATUS_RESIZING }, () => {
5571
raf.cancel(this.resizeFrameId);
5672
this.resizeFrameId = raf(() => {
57-
this.setState({ resizing: false });
58-
this.fixFirefoxAutoScroll();
73+
this.setState({ resizeStatus: RESIZE_STATUS_RESIZED }, () => {
74+
this.resizeFrameId = raf(() => {
75+
this.setState({ resizeStatus: RESIZE_STATUS_NONE });
76+
this.fixFirefoxAutoScroll();
77+
});
78+
});
5979
});
6080
});
6181
},
@@ -77,7 +97,7 @@ const ResizableTextArea = {
7797
renderTextArea() {
7898
const props = getOptionProps(this);
7999
const { prefixCls, autoSize, autosize, disabled } = props;
80-
const { textareaStyles, resizing } = this.$data;
100+
const { textareaStyles, resizeStatus } = this.$data;
81101
warning(
82102
autosize === undefined,
83103
'Input.TextArea',
@@ -104,7 +124,9 @@ const ResizableTextArea = {
104124
}
105125
const style = {
106126
...textareaStyles,
107-
...(resizing ? { overflowX: 'hidden', overflowY: 'hidden' } : null),
127+
...(resizeStatus === RESIZE_STATUS_RESIZING
128+
? { overflowX: 'hidden', overflowY: 'hidden' }
129+
: null),
108130
};
109131
const textareaProps = {
110132
attrs: otherProps,
@@ -119,7 +141,7 @@ const ResizableTextArea = {
119141
],
120142
};
121143
return (
122-
<ResizeObserver onResize={this.resizeOnNextFrame} disabled={!(autoSize || autosize)}>
144+
<ResizeObserver onResize={this.handleResize} disabled={!(autoSize || autosize)}>
123145
<textarea {...textareaProps} ref="textArea" />
124146
</ResizeObserver>
125147
);

components/input/calculateNodeHeight.js

-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ export default function calculateNodeHeight(
142142
height = Math.min(maxHeight, height);
143143
}
144144
}
145-
// // Remove scroll bar flash when autosize without maxRows
146-
// // donot remove in vue
147-
// if (!maxRows) {
148-
// overflowY = 'hidden';
149-
// }
150145
return {
151146
height: `${height}px`,
152147
minHeight: `${minHeight}px`,

0 commit comments

Comments
 (0)