SearchBar

The search function allows text query for the users. On basis of the current page contents, the user can perform exact search or fuzzy search to filter and locate contents and increase productivity in queries. When the search bar is activated, the cancel button appears. Note: For the purpose of UI presentation only. No service logic function is available.

Sample Code

copy
	// API-DEMO page/component/search-bar/search-bar.json
	{
	  "defaultTitle": "Mini Program AntUI component library",
	  "usingComponents": {
	    "search-bar": "mini-antui/es/search-bar/index"
	  }
	}
copy
	<!-- API-DEMO page/component/search-bar/search-bar.axml -->
	<view>
	  <search-bar
	    value="{{value}}"
	    placeholder="Search "
	    onInput="handleInput"
	    onClear="handleClear"
	    onFocus="handleFocus"
	    onBlur="handleBlur"
	    onCancel="handleCancel"
	    onSubmit="handleSubmit"
	    showCancelButton="{{false}}" />
	</view>
copy
	// API-DEMO page/component/search-bar/search-bar.js
	Page({
	  data: {
	    value: 'Food',
	  },
	  handleInput(value) {
	    this.setData({
	      value,
	    });
	  },
	  handleClear(value) {
	    this.setData({
	      value: '',
	    });
	  },
	  handleFocus() {},
	  handleBlur() {},
	  handleCancel() {
	    this.setData({
	      value: '',
	    });
	  },
	  handleSubmit(value) {
	    my.alert({
	      content: value,
	    });
	  },
	});

Attributes

Property

DescriptionTypeDefault

Required

valueCurrent value in search box.String-No
placeholderPlaceholder.String-No
focusGet cursor automatically.BooleanfalseNo
onInputTrigger on keyboard input.(value: String) => void-No
onClearTrigger on clicking clear icon.(val: String) => void-No
onFocusTrigger on getting focus.() => void-No
onBlurTrigger on losing focus.() => void-No
onCancelTrigger on clicking cancel.() => void-No
onSubmitTrigger on clicking enter on button.(val: String) => void-No
disabledSet disabled.Boolean-No
maxLengthMaximum number of characters allowed for input Number.-No
showCancelButtonAlways show cancel button or not.Boolean-No