@@ -8,9 +8,14 @@ import type { TextAreaProps } from '.';
8
8
import calculateAutoSizeStyle from './calculateNodeHeight' ;
9
9
import type { ResizableTextAreaRef } from './interface' ;
10
10
11
- const RESIZE_START = 0 ;
12
- const RESIZE_MEASURING = 1 ;
13
- const RESIZE_STABLE = 2 ;
11
+ const RESIZE_START = 0 as const ;
12
+ const RESIZE_MEASURING = 1 as const ;
13
+ const RESIZE_STABLE = 2 as const ;
14
+
15
+ type ResizeState =
16
+ | typeof RESIZE_START
17
+ | typeof RESIZE_MEASURING
18
+ | typeof RESIZE_STABLE ;
14
19
15
20
const ResizableTextArea = React . forwardRef < ResizableTextAreaRef , TextAreaProps > (
16
21
( props , ref ) => {
@@ -62,34 +67,9 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
62
67
63
68
const needAutoSize = ! ! autoSize ;
64
69
65
- // =============================== Scroll ===============================
66
- // https://github.com/ant-design/ant-design/issues/21870
67
- const fixFirefoxAutoScroll = ( ) => {
68
- try {
69
- const isFirefox = navigator . userAgent . includes ( 'Firefox' ) ;
70
- // FF has bug with jump of scroll to top. We force back here.
71
- if ( isFirefox && document . activeElement === textareaRef . current ) {
72
- const { scrollTop, selectionStart, selectionEnd } =
73
- textareaRef . current ;
74
-
75
- // Fix Safari bug which not rollback when break line
76
- // This makes Chinese IME can't input. Do not fix this
77
- // const { value: tmpValue } = textareaRef.current;
78
- // textareaRef.current.value = '';
79
- // textareaRef.current.value = tmpValue;
80
-
81
- textareaRef . current . setSelectionRange ( selectionStart , selectionEnd ) ;
82
- textareaRef . current . scrollTop = scrollTop ;
83
- }
84
- } catch ( e ) {
85
- // Fix error in Chrome:
86
- // Failed to read the 'selectionStart' property from 'HTMLInputElement'
87
- // http://stackoverflow.com/q/21177489/3040605
88
- }
89
- } ;
90
-
91
70
// =============================== Resize ===============================
92
- const [ resizeState , setResizeState ] = React . useState ( RESIZE_STABLE ) ;
71
+ const [ resizeState , setResizeState ] =
72
+ React . useState < ResizeState > ( RESIZE_STABLE ) ;
93
73
const [ autoSizeStyle , setAutoSizeStyle ] =
94
74
React . useState < React . CSSProperties > ( ) ;
95
75
@@ -133,7 +113,8 @@ const ResizableTextArea = React.forwardRef<ResizableTextAreaRef, TextAreaProps>(
133
113
setResizeState ( RESIZE_STABLE ) ;
134
114
setAutoSizeStyle ( textareaStyles ) ;
135
115
} else {
136
- fixFirefoxAutoScroll ( ) ;
116
+ // https://github.com/react-component/textarea/pull/23
117
+ // Firefox has blink issue before but fixed in latest version.
137
118
}
138
119
} , [ resizeState ] ) ;
139
120
0 commit comments