Skip to main content

SearchBar

Effect demonstration

1. Default allocation

<SearchBar
onChange={(value) => console.log(value)}
onSearch={(value) => console.log(value)}
/>
searchBar-ios1.png

2. Configuration placeholder、cancelTitle

<SearchBar placeholder="Please enter hotel/keyword" cancelText="cancel" />
searchBar-ios2.png

3. Configuration defaultValue、autoFocus

<SearchBar defaultValue="NewYork Hotel" autoFocus />
searchBar-ios4.png

4. Configuration children

<SearchBar inputStyle={{ flex: 6 }} style={{ height: px(56) }}>
<>
<Flex flex={1}>
<SvgIcon name="left" size={24} />
</Flex>
<Flex flex={2} height={px(40)} justifyContent="center">
<Text>Please check in</Text>
</Flex>
</>
</SearchBar>
searchBar-ios5.png

API

PropertiesRequiredDescriptionTypeDefault Value
placeholderfalseplaceholder for the search boxstringsearch
showCancelButtonfalseWhether to display the cancel buttonbooleantrue
allowClearfalseWhether to allow clearingbooleantrue
disabledfalseWhether the search box is disabledbooleanfalse
defaultValuefalseThe default value of the search boxstring
autoFocusfalseWhether to automatically focusbooleanfalse
cancelTextfalseCancel textstringCancel
returnKeyTypefalseThe button type below the keyboardReturnKeyTypeOptionssearch
keyboardTypefalsePopup keyboard typeKeyboardTypeOptionsdefault
stylefalseThe style of the outermost viewViewStyle
inputStylefalseinput styleTextStyle
onChangefalseCallback when input changes(text: string) => void
onSearchfalseSearch on submission(text: string) => void
activeOpacityfalseThe opacity of the cancel button when pressednumber0.6