Combobox
Installation
yarn add @spark-web/combobox
The Combobox
allows the user to browse, search, and make a single selection
from a large list of values.
Usage
Controlled component
Uncontrolled component
Async
Custom label and value
Grouped
With Default Option
Appearance
Disabled
Invalid
Props
Prop | Type | Description |
---|---|---|
items | Awaitable<(Item | GroupBase<Item>)[]> | Array of items for the user to select from. |
data? | DataAttributeMap | Sets data attributes on the component. |
defaultOption? | DefaultOption<Item> | Option that will be displayed regardless of filter results |
getOptionLabel? | GetOptionLabel<Item> | Resolves option data to a string to be displayed as the label by components. Note: Failure to resolve to a string type can interfere with filtering and screen reader support. |
getOptionValue? | GetOptionValue<Item> | Resolves option data to a string to compare options and specify value attributes. |
inputValue? | string | The value of the input. |
isLoading? | boolean | When true, shows a loading indicator in the dropdown instead of results. |
menuPortalTarget? | HTMLElement | Whether the menu should use a portal, and where it should attach. |
onChange? | (value: Item) => void | Called when an item is selected. |
onInputChange? | (inputValue: string) => void | Called whenever the input value changes. Use to filter the items. |
placeholder? | string | The text that appears in the form control when it has no value set. |
value? | Item | The selected item. |