Skip to main content
Version: 4.0.0-rc.1

SearchBar

Usage

iOS

Android

Interaction methods

methoddescription
focuscall focus on the textinput (example)
blurcall blur on the textinput (example)
clearcall clear on the textinput (example)
cancel(Android and iOS SearchBars only) call cancel on the SearchBar (left arrow on Android, Cancel button on iOS). This will basically blur the input and hide the keyboard (example)

Store a reference to the SearchBar in your component by using the ref prop provided by React (see docs):

<SearchBar
ref={search => this.search = search}
...
/>

You can then access SearchBar methods like so:

this.search.focus();
this.search.blur();
this.search.clear();
this.search.cancel(); // Only available if `platform` props is "ios" | "android"

Props

note

Includes all Input, SearchBarBase props.

NameTypeDefaultDescription
cancelButtonPropsText Style
cancelButtonTitlestring
cancelIconIconNode
clearIconIconNode or ({ name: string; } & IconNode)
containerStyleView Style
inputContainerStyleView Style
inputStyleText Style
leftIconContainerStyleView Style
lightThemeboolean
loadingPropsActivityIndicatorProps
onBlur(() => void) or (((e: NativeSyntheticEvent<TextInputFocusEventData>) => void) & (() => void)) or ((() => any) & (() => void) & ((e: NativeSyntheticEvent<TextInputFocusEventData>) => void)) or ((() => any) & ... 1 more ... & (() => void))Callback that is called when the text input is blurred
onCancel(() => void) or ((() => any) & (() => void))
onChangeText((text: string) => void) or (((text: string) => void) & ((text: string) => void)) or ((() => any) & ((text: string) => void) & ((text: string) => void)) or ((() => any) & ((text: string) => void) & ((text: string) => void))Callback that is called when the text input's text changes.Changed text is passed as an argument to the callback handler.
onClear(() => void) or ((() => any) & (() => void)) or ((() => any) & (() => void))
onFocus(() => void) or (((e: NativeSyntheticEvent<TextInputFocusEventData>) => void) & (() => void)) or ((() => any) & (() => void) & ((e: NativeSyntheticEvent<TextInputFocusEventData>) => void)) or ((() => any) & ... 1 more ... & (() => void))Callback that is called when the text input is focused
platformdefault or ios or android'default' as const
rightIconContainerStyleView Style
roundboolean
searchIconIconNode or ({ name: string; } & IconNode)
showCancelboolean
showLoadingboolean