@@ -149,7 +149,7 @@ export type Props = React.ComponentPropsWithRef<typeof TextInput> & {
149149
150150type TextInputHandles = Pick <
151151 TextInput ,
152- 'setNativeProps' | 'isFocused' | 'clear' | 'blur' | 'focus'
152+ 'setNativeProps' | 'isFocused' | 'clear' | 'blur' | 'focus' | 'setSelection'
153153> ;
154154
155155/**
@@ -210,31 +210,16 @@ const Searchbar = forwardRef<TextInputHandles, Props>(
210210 const theme = useInternalTheme ( themeOverrides ) ;
211211 const root = React . useRef < TextInput > ( null ) ;
212212
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+ } ) ) ;
238223
239224 const handleClearPress = ( e : any ) => {
240225 root . current ?. clear ( ) ;
0 commit comments