@@ -9,6 +9,10 @@ import inputProps from './inputProps';
9
9
import PropTypes from '../_util/vue-types' ;
10
10
import { getOptionProps , getListeners } from '../_util/props-util' ;
11
11
12
+ const RESIZE_STATUS_NONE = 0 ;
13
+ const RESIZE_STATUS_RESIZING = 1 ;
14
+ const RESIZE_STATUS_RESIZED = 2 ;
15
+
12
16
const TextAreaProps = {
13
17
...inputProps ,
14
18
autosize : PropTypes . oneOfType ( [ Object , Boolean ] ) ,
@@ -20,7 +24,7 @@ const ResizableTextArea = {
20
24
data ( ) {
21
25
return {
22
26
textareaStyles : { } ,
23
- resizing : false ,
27
+ resizeStatus : RESIZE_STATUS_NONE ,
24
28
} ;
25
29
} ,
26
30
mixins : [ BaseMixin ] ,
@@ -39,6 +43,18 @@ const ResizableTextArea = {
39
43
} ,
40
44
} ,
41
45
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
+ } ,
42
58
resizeOnNextFrame ( ) {
43
59
raf . cancel ( this . nextFrameActionId ) ;
44
60
this . nextFrameActionId = raf ( this . resizeTextarea ) ;
@@ -51,11 +67,15 @@ const ResizableTextArea = {
51
67
}
52
68
const { minRows, maxRows } = autoSize ;
53
69
const textareaStyles = calculateNodeHeight ( this . $refs . textArea , false , minRows , maxRows ) ;
54
- this . setState ( { textareaStyles, resizing : true } , ( ) => {
70
+ this . setState ( { textareaStyles, resizeStatus : RESIZE_STATUS_RESIZING } , ( ) => {
55
71
raf . cancel ( this . resizeFrameId ) ;
56
72
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
+ } ) ;
59
79
} ) ;
60
80
} ) ;
61
81
} ,
@@ -77,7 +97,7 @@ const ResizableTextArea = {
77
97
renderTextArea ( ) {
78
98
const props = getOptionProps ( this ) ;
79
99
const { prefixCls, autoSize, autosize, disabled } = props ;
80
- const { textareaStyles, resizing } = this . $data ;
100
+ const { textareaStyles, resizeStatus } = this . $data ;
81
101
warning (
82
102
autosize === undefined ,
83
103
'Input.TextArea' ,
@@ -104,7 +124,9 @@ const ResizableTextArea = {
104
124
}
105
125
const style = {
106
126
...textareaStyles ,
107
- ...( resizing ? { overflowX : 'hidden' , overflowY : 'hidden' } : null ) ,
127
+ ...( resizeStatus === RESIZE_STATUS_RESIZING
128
+ ? { overflowX : 'hidden' , overflowY : 'hidden' }
129
+ : null ) ,
108
130
} ;
109
131
const textareaProps = {
110
132
attrs : otherProps ,
@@ -119,7 +141,7 @@ const ResizableTextArea = {
119
141
] ,
120
142
} ;
121
143
return (
122
- < ResizeObserver onResize = { this . resizeOnNextFrame } disabled = { ! ( autoSize || autosize ) } >
144
+ < ResizeObserver onResize = { this . handleResize } disabled = { ! ( autoSize || autosize ) } >
123
145
< textarea { ...textareaProps } ref = "textArea" />
124
146
</ ResizeObserver >
125
147
) ;
0 commit comments