@@ -149,7 +149,7 @@ export type Props = React.ComponentPropsWithRef<typeof TextInput> & {
149
149
150
150
type TextInputHandles = Pick <
151
151
TextInput ,
152
- 'setNativeProps' | 'isFocused' | 'clear' | 'blur' | 'focus'
152
+ 'setNativeProps' | 'isFocused' | 'clear' | 'blur' | 'focus' | 'setSelection'
153
153
> ;
154
154
155
155
/**
@@ -210,31 +210,16 @@ const Searchbar = forwardRef<TextInputHandles, Props>(
210
210
const theme = useInternalTheme ( themeOverrides ) ;
211
211
const root = React . useRef < TextInput > ( null ) ;
212
212
213
- React . useImperativeHandle ( ref , ( ) => {
214
- const input = root . current ;
215
-
216
- if ( input ) {
217
- return {
218
- focus : ( ) => input . focus ( ) ,
219
- clear : ( ) => input . clear ( ) ,
220
- setNativeProps : ( args : TextInputProps ) => input . setNativeProps ( args ) ,
221
- isFocused : ( ) => input . isFocused ( ) ,
222
- blur : ( ) => input . blur ( ) ,
223
- } ;
224
- }
225
-
226
- const noop = ( ) => {
227
- throw new Error ( 'TextInput is not available' ) ;
228
- } ;
229
-
230
- return {
231
- focus : noop ,
232
- clear : noop ,
233
- setNativeProps : noop ,
234
- isFocused : noop ,
235
- blur : noop ,
236
- } ;
237
- } ) ;
213
+ React . useImperativeHandle ( ref , ( ) => ( {
214
+ focus : ( ) => root . current ?. focus ( ) ,
215
+ clear : ( ) => root . current ?. clear ( ) ,
216
+ setNativeProps : ( args : TextInputProps ) =>
217
+ root . current ?. setNativeProps ( args ) ,
218
+ isFocused : ( ) => root . current ?. isFocused ( ) || false ,
219
+ blur : ( ) => root . current ?. blur ( ) ,
220
+ setSelection : ( start : number , end : number ) =>
221
+ root . current ?. setSelection ( start , end ) ,
222
+ } ) ) ;
238
223
239
224
const handleClearPress = ( e : any ) => {
240
225
root . current ?. clear ( ) ;
0 commit comments