Events#
Search components use the events of their underlying components. All support onFocus, onBlur, onClear, and onSubmit.
Search.Input#
Use onChange to receive query changes and onSubmit to handle Enter. Both receive an object containing value and event.
Inside a form, Enter also submits the form, as in any native search input. Call event.preventDefault() in onSubmit to handle the query without submitting the form. Search.Autocomplete and Search.Panel do not submit a surrounding form.
| Type | Description | |
|---|---|---|
onChange | function | (optional) Will be called on value changes made by the user. Returns an object with the value as a string and the native event: { value, event }. |
onFocus | function | (optional) Will be called on focus set by the user. Returns { value, event }. |
onKeyDown | function | (optional) Will be called on key down by the user. Returns { value, event }. |
onBlur | function | (optional) Will be called on blur set by the user. Returns { value, event }. |
onSubmit | function | (optional) Will be called on enter key press, and on submit button click when a submit button is shown. Returns { value, event }. |
onSubmitFocus | function | (optional) Will be called on submit button focus. Only relevant when a submit button is shown. Returns { value, event }. Not called in Safari, which only focuses buttons on Tab or click when "Press Tab to highlight each item on a web page" is enabled in the Advanced settings in Safari. |
onSubmitBlur | function | (optional) Will be called on submit button blur. Only relevant when a submit button is shown. Returns { value, event }. Not called in Safari, which only focuses buttons on Tab or click when "Press Tab to highlight each item on a web page" is enabled in the Advanced settings in Safari. |
onClear | function | (optional) Will be called on a clear button click. Returns { value, previousValue, event }. |
See Input events for details about changing or preventing an input value.
Search.Autocomplete and Search.Panel#
Use onType to receive query changes and load suggestions. Use onChange to handle a confirmed result, and onSelect to follow the active result during keyboard navigation.
onSubmit handles Enter when no result is active or selected. Selecting a result keeps the query by default.
With mode="async", use updateData when results arrive and showNoOptionsItem when the search returns no results. showIndicator displays loading inside the input without opening an empty panel. Clearing an asynchronous query should clear the data, hide loading, and ignore any pending response.
| Type | Description | |
|---|---|---|
onType | function | (optional) Will be called for every key change the user makes. Returns an object with the input value inside { value, event, attributes } including these methods. |
onFocus | function | (optional) Will be called on user generated focus action. Returns an object with the input value inside { value, event, attributes } including these methods. |
onBlur | function | (optional) Will be called on user generated blur action. Returns an object with the input value inside { value, event, attributes } including these methods. |
onChange | function | (optional) Will be called on state changes made by the user. Returns an object with the new selected data item { data, event, attributes, value } including these methods. |
onSelect | function | (optional) Will be called once the user focuses or selects an item by a click or keyboard navigation. Returns an object with the new selected data item { data, event, attributes, value, activeItem, selectedItem } including these methods. The "activeItem" property is the currently selected item by keyboard navigation. |
onOpen | function | (optional) Will be called once the user presses the autocomplete. Returns the data item { data, attributes }. |
onClose | function | (optional) Will be called once the user presses the autocomplete again, or clicks somewhere else. Returns the data item { data, attributes }. |
onClear | function | (optional) Will be called on a clear button click. Returns { value, previousValue, event }. |
onSubmit | function | (optional) Will be called when the user presses Enter in the input field without selecting an item from the list. Useful for triggering custom actions like navigating to a search results page. Returns { value, event, attributes } including these methods. |
onItemMouseEnter | function | (optional) Will be called when the mouse enters a dropdown item. Useful for pre-fetching data on hover. Returns { item, data, event } where item is the item index and data is the item data. |
The callbacks also provide methods such as updateData, showIndicator, hideIndicator, and setHidden. Search.Panel also passes close to its children render function for custom actions that close the surface. See Autocomplete events and dynamically changing data.