A text input with a dropdown list of options.
The component can be imported via:
A complete example of Combobox usage can be seen below, with the following arguments:
inputValue - the string text value to show inside the ComboboxselectedValue - they key of the currently selected dropdown optiononValueChange - a callback for when the inputValue changesonSelectionChange - a callback for when an option is selected in the dropdownoptions - an array of options, with the same shape as in PlumaSelectThe Combobox accepts separate arguments for the text value shown in the input (inputValue),
and for the dropdown option that is currently selected (selectedValue). It also
accepts corresponding change callbacks: onValueChange and onSelectionChange respectively.
The component can be used with either inputValue or selectedValue arguments,
or with both at the same time, depending on use case.
This is the recommended setup, and allows developers to fully control the input
and dropdown state, by passing in both inputValue and selectedValue, and their
appropriate change handlers.
Note that an update to one of these values does not automatically update the other.
This means that typing in the input will only invoke the onValueChange handler,
while selecting an option in the dropdown will only call onSelectionChange.
The developer must make sure to update the other property when one of them changes.
selectedValue-only controlWhen only selectedValue is controlled, the component will set its internal input
value to the selected option's label whenever an option is selected.
inputValue-only controlWhen only inputValue is controlled, the component will internally track the state
of the selected dropdown option, and update it whenever a selection has been made (
either through pressing the Enter key or by clicking on an option).
On blur, the component will reset the selected value to an option with a matching
label text, or null if no matching option is found.
Individual options can be disabled:
You can pass in groups of options to the Combobox to create breaks between sets of options:
An entire group can be disabled by setting its option entry to isDisabled:
Just like the Select component, Combobox supports virtualized option rendering.
This option is disabled by default, and can be enabled via the withVirtualizer argument.
Optionally, the virtualizerOptions argument accepts the same options as the library's
Virtualizer class,
allowing you to customize the behavior if necessary.
The Combobox component accepts an optionComponent prop,
which can be used to customize how the options in the dropdown are rendered.
The prop accepts a component, which will be called with the following props:
option - the option object from the options arrayisSelected - whether this is the currently selected option (the selectedValue matches this option)isActive - whether this is the currently active option (it's currently hovered or focused via keyboard)For example, we might define a custom option component like this:
Which could then be used in the Combobox component:
The Combobox component supports loading options data asynchronously. It will display
a loading spinner inside the input when isLoading is true. When performing
filtering through an API, also set shouldFilter to false, to prevent the
Combobox from filtering the results itself.
The Combobox also supports infinite scrolling (for paginated APIs), and will call
the onLoadMore callback when scrolling towards the end of the list. The other
props expected for this use case are:
shouldLoadMore - a boolean indicating whether the onLoadMore callback should
be called at all (e.g. when there is a next page of data). Set to false if there
are no more pages/there is no more data to fetchisLoadingMore - whether more data is currently being fetched. While the API call
issued via the onLoadMore callback is running, this should be true, and will
show a loading spinner at the bottom of the listNote: It is up to you to merge the results of the paginated API calls into one
options array, which you pass into the component. The component itself only issues
callbacks when required, but you control the state.
The example below shows a Combobox that simulates an API with filtering and pagination.
If a string label is not sufficient, a component can be used to render the label.
In React, the label prop accepts any ReactNode.
If a string description is not sufficient, a component can be used to render the description.
In React, the description prop accepts any ReactNode.
If a string error is not sufficient, a component can be used to render the error.
In React, the error prop accepts any ReactNode.
PlumaCombobox extends BoxAdditional middleware to apply to Floating UI, for example custom middleware for more control. These will be applied after the default middleware.
Element (or elements) that describe the form field. Also used for error messages, as aria-errormessage isn't supported in all assistive technologies: https://a11ysupport.io/tech/aria/aria-errormessage_attribute
String value that labels the form field.
Element (or elements) that label the form field.
Focuses automatically when the component is rendered. Should be used with care and only sparingly, as there are some accessibility concerns. More information here
Additional classes to be applied to the top-level container. This is necessary as an argument in Ember, where we apply splattributes on the "input" itself, which means we can't pass a custom class to the containing element the classic way.
A description for the field, providing additional context or hints.
An error message associated with the form field.
Boolean: Ember-only. If the error named block is used,
this prop can be set to true to indicate an error is present,
which will make the error block render.
The component to render at the header of the menu (before the search input, if present).
The name of an icon (from Pluma Icons) to be rendered on the left side of the input.
Default:subtle
A color to apply to the icon.
An optional id to be assigned to the input element. Also used to generate ids for labels and error messages. If one isn't provided, it will be generated.
The current string value in the text field.
Whether the input element is clearable.
Whether the form field is disabled.
Whether the form field is in an invalid state.
Whether the input should show a loading spinner.
Whether more options are currently being loaded.
The label text to show with the form field.
The name attribute is used for HTML forms
Called when the active (currently highlighted, but not necessarily selected) option changes when the dropdown is open.
The blur event handler for the input element.
The change event handler for the input element.
In addition to isClearable, this function is required to render the clear button.
This will be called when the clear button is clicked.
Called when the dropdown finishes closing (after the close animation finishes).
The focus event handler for the input element.
The input event handler for the input element.
Callback for when the end of the dropdown is reached and more options should be loaded.
Called when the dropdown is opened.
Callback when the open state should change.
The callback for when an option is selected.
The callback for when the input's value changes.
The component to render for each option in the menu.
An array of options to render.
Placeholder text to show inside the field.
The current selected option value (the value of the selected option item).
Whether to allow browser autofill and password managers. When false (default), adds attributes to disable password managers (1Password, LastPass, Bitwarden, Dashlane). Set to true for fields where autofill is desired (e.g., email, password, address fields).
Whether the generated description id should be included in the input's aria-describedby attribute.
Disable this when a label`` tag surrounds the input as well as it's description text, for example in an OptionCard` component.
Whether the generated label id should be included in the input's aria-labelledby attribute.
Disable this when the label tag surrounds the input as well as it's label text,
for example in an OptionCard component.
Default:true
Whether the component should filter the options based on the input value.
Set to false if you want to handle the filtering yourself, for
example when the options are fetched and filtered via an API.
Whether the onLoadMore callback should be called when the end of the dropdown is reached. If no more paginated options are available, this should be set to false.
Default:false
Whether the dropdown should open when the input is focused.
By default, form elements will throw an error if no label or aria-label is provided. Disable this to suppress the error, for example when building a custom form element, and you want to handle labeling yourself.
The size of the input element.
Additional classes to be applied to the description element.
Additional classes to be applied to the error element.
Additional classes to be applied to the field node.
Ember-only: this is used internally to detect whether a label
named block is present, and to ignore empty label props if so.
Additional classes to be applied to the input node.
Sets the size attribute on the input element. This controls the visible width of the input in characters.
Whether the component should render with "legacy" styles.
Additional classes to be applied to the label node.
Additional size configuration for the popover component. Can be used to e.g. restrict the maxWidth of the popover. If the value of one of the keys is a function, it will be called with the default values that PlumaCombobox would use (with numbers representing pixel values).
Options, or a function that returns options, for the Virtualizer.
Whether to apply the center-baseline variant.
Show tooltip only when label is truncated, for all options and group headers. Can be overridden per-option or per-group.
Whether the menu options should render in a virtualized list.