Search Bar
Allow users to enter a query or keyword to search through content within a website.
Usage
Examples
Size
Use the size prop to change the search bar's size.
Clear Button
You can use SearchBarClearButton to show a clear button.
Hint
Show a hint with SearchBarHint.
Show Search Results or Suggestions
You can show search results or suggestions with the SearchBarResults, SearchBarResultsList and SearchBarResultsItem components.
You can also group results with the SearchBarResultsGroup component:
Controlled Component
The search bar must be controlled with props:
- Set the
valueandonValueChangeprops forSearchBarInput - Set the
openprop forSearchBarResults
In the example below, we also keep track of whether the search bar is focused or not with a hasFocus state. This lets us open or close SearchBarResults based on the input's value and focus state.
Props
SearchBar
SearchBar is abstracted from cmdk's Command.Root. Please refer to the API references in this documentation.
| Prop | Type | Default |
|---|---|---|
size | enum | medium |
SearchBarInput
SearchBarInput is abstracted from cmdk's Command.Input. Please refer to the API references in this documentation
| Prop | Type | Default |
|---|---|---|
value | string | - |
onValueChange | function | - |
SearchBarInputContainer
SearchBarInputContainer uses the same props as a regular div element.
SearchBarSearchButton
SearchBarSearchButton uses the same props as MYDS' Button. Please refer to the API references in this documentation
SearchBarClearButton
SearchBarClearButton uses the same props as MYDS' Button. Please refer to the API references in this documentation
SearchBarHint
SearchBarInputContainer uses the same props as a regular div element.
SearchBarResults
| Prop | Type | Default |
|---|---|---|
open | boolean | - |
SearchBarResultsList
SearchBarResultsList is abstracted from cmdk's Command.List. Please refer to the API references in this documentation
SearchBarResultsItem
SearchBarResultsItem is abstracted from cmdk's Command.Item. Please refer to the API references in this documentation
SearchBarResultsGroup
SearchBarResultsGroup is abstracted from cmdk's Command.Group. Please refer to the API references in this documentation