@@ -167,25 +167,27 @@ const TextInput: React.AbstractComponent<
167
167
const dimensions = React . useRef ( { height : null , width : null } ) ;
168
168
const hostRef = React . useRef ( null ) ;
169
169
170
- const handleContentSizeChange = React . useCallback ( ( ) => {
171
- const node = hostRef . current ;
172
- if ( multiline && onContentSizeChange && node != null ) {
173
- const newHeight = node . scrollHeight ;
174
- const newWidth = node . scrollWidth ;
175
- if ( newHeight !== dimensions . current . height || newWidth !== dimensions . current . width ) {
176
- dimensions . current . height = newHeight ;
177
- dimensions . current . width = newWidth ;
178
- onContentSizeChange ( {
179
- nativeEvent : {
180
- contentSize : {
181
- height : dimensions . current . height ,
182
- width : dimensions . current . width
170
+ const handleContentSizeChange = React . useCallback (
171
+ ( hostNode ) => {
172
+ if ( multiline && onContentSizeChange && hostNode != null ) {
173
+ const newHeight = hostNode . scrollHeight ;
174
+ const newWidth = hostNode . scrollWidth ;
175
+ if ( newHeight !== dimensions . current . height || newWidth !== dimensions . current . width ) {
176
+ dimensions . current . height = newHeight ;
177
+ dimensions . current . width = newWidth ;
178
+ onContentSizeChange ( {
179
+ nativeEvent : {
180
+ contentSize : {
181
+ height : dimensions . current . height ,
182
+ width : dimensions . current . width
183
+ }
183
184
}
184
- }
185
- } ) ;
185
+ } ) ;
186
+ }
186
187
}
187
- }
188
- } , [ hostRef , multiline , onContentSizeChange ] ) ;
188
+ } ,
189
+ [ multiline , onContentSizeChange ]
190
+ ) ;
189
191
190
192
const imperativeRef = React . useMemo (
191
193
( ) => ( hostNode ) => {
@@ -201,7 +203,7 @@ const TextInput: React.AbstractComponent<
201
203
hostNode . isFocused = function ( ) {
202
204
return hostNode != null && TextInputState . currentlyFocusedField ( ) === hostNode ;
203
205
} ;
204
- handleContentSizeChange ( ) ;
206
+ handleContentSizeChange ( hostNode ) ;
205
207
}
206
208
} ,
207
209
[ handleContentSizeChange ]
@@ -216,9 +218,10 @@ const TextInput: React.AbstractComponent<
216
218
}
217
219
218
220
function handleChange ( e ) {
219
- const text = e . target . value ;
221
+ const hostNode = e . target ;
222
+ const text = hostNode . value ;
220
223
e . nativeEvent . text = text ;
221
- handleContentSizeChange ( ) ;
224
+ handleContentSizeChange ( hostNode ) ;
222
225
if ( onChange ) {
223
226
onChange ( e ) ;
224
227
}
@@ -228,26 +231,27 @@ const TextInput: React.AbstractComponent<
228
231
}
229
232
230
233
function handleFocus ( e ) {
231
- const node = hostRef . current ;
234
+ const hostNode = e . target ;
232
235
if ( onFocus ) {
233
- e . nativeEvent . text = e . target . value ;
236
+ e . nativeEvent . text = hostNode . value ;
234
237
onFocus ( e ) ;
235
238
}
236
- if ( node != null ) {
237
- TextInputState . _currentlyFocusedNode = node ;
239
+ if ( hostNode != null ) {
240
+ TextInputState . _currentlyFocusedNode = hostNode ;
238
241
if ( clearTextOnFocus ) {
239
- node . value = '' ;
242
+ hostNode . value = '' ;
240
243
}
241
244
if ( selectTextOnFocus ) {
242
245
// Safari requires selection to occur in a setTimeout
243
246
setTimeout ( ( ) => {
244
- node . select ( ) ;
247
+ hostNode . select ( ) ;
245
248
} , 0 ) ;
246
249
}
247
250
}
248
251
}
249
252
250
253
function handleKeyDown ( e ) {
254
+ const hostNode = e . target ;
251
255
// Prevent key events bubbling (see #612)
252
256
e . stopPropagation ( ) ;
253
257
@@ -274,8 +278,8 @@ const TextInput: React.AbstractComponent<
274
278
nativeEvent . text = e . target . value ;
275
279
onSubmitEditing ( e ) ;
276
280
}
277
- if ( shouldBlurOnSubmit && hostRef . current != null ) {
278
- hostRef . current . blur ( ) ;
281
+ if ( shouldBlurOnSubmit && hostNode != null ) {
282
+ hostNode . blur ( ) ;
279
283
}
280
284
}
281
285
}
0 commit comments