Single Select Menu
Input control allowing for choosing single option from searchable options menu.
SingleSelectMenu
is built on top of
Select Menu parts
which provide core functionality of the component.
It is interchangable with the native Select component, but prettier and more powerful.
#
Importimport { SingleSelectMenu } from '@volue/wave-react';
Single Select Menu is a compound component that consists of multiple parts:
-
SingleSelectMenu
: The wrapper that contains all the parts of a select menu and provides context for its children. -
SingleSelectMenu.Trigger
: The button that toggles the select menu. -
SingleSelectMenu.Content
: A wrapper for the content to be rendered when the select menu is open. It positions itself by aligning overSingleSelectMenu.Trigger
. -
SingleSelectMenu.Clear
: The button that clears the value of select menu. -
SingleSelectMenu.Item
: A container for select menu's item of choice. -
SingleSelectMenu.ItemText
: A wrapper around textual part ofSingleSelectMenu.Item
. -
SingleSelectMenu.ItemIndicator
: A visual cue in form of an icon that is displayed when the item is selected. -
SingleSelectMenu.Group
: A wrapper for the group of select menu items. -
SingleSelectMenu.Label
: The component that renders an accessible label ofSingleSelectMenu.Group
. -
SingleSelectMenu.Separator
: The component that renders a horizontal divider between menu items and groups.
#
Examples#
BasicProvide placeholder
prop when the select input does not have an initial value.
SingleSelectMenu
has built in typeahead behavior, meaning pressing the letter B will jump to and highlight the word "Banana" in the example below.
#
With a default valueWhen using SingleSelectMenu
in "uncontrolled" mode, you can specify the default selected option with defaultValue
property.
#
ControlledYou can easily make the SingleSelectMenu
controlled, by passing your own state to value
prop. onValueChange
handler is called when
the selected value changes, allowing you to sync state.
#
With a clear buttonUse SingleSelectMenu.Clear
part to render a button that clears the value of the select menu.
Focus will automatically move back to the select menu trigger after the value is cleared.
#
DisabledThe component can use isDisabled
prop to prevent user from interacting, but also single items can be disabled to limit user's choice.
#
With Form FieldUse Form Field component to enhance SingleSelectMenu
with: an accessible label, an optional helper text, a feedback message or to show required indicator.
It is recommended to wrap select inputs with Form Field to create a consistent set of accessible form fields.
The Form Field automatically generates a unique id that links the SingleSelectMenu
with the FormField.Label
.
When using SingleSelectMenu
without Form Field, be mindful to provide aria-label
for SingleSelectMenu.Trigger
.
#
SizesSingleSelectMenu
comes in two size variants: medium
and small
, with the medium
size used by default. All sizes are aligned with sizes of other related components like Text Input.
#
Customized appearanceSingleSelectMenu.Trigger
and SingleSelectMenu.Item
can be decorated with supporting icons or elements using startElement
and endElement
props.
#
Active indicatorsWhen item inside the Single Select Menu is selected its text content is highligted in bold.
For additional emphasis you may include SingleSelectMenu.ItemIndicator
to add a visual indicator rendered when the item is selected.
#
Custom render valueBy default, SingleSelectMenu.Trigger
will automatically display the selected item text content.
However you can take control over the rendering by providing a function to the renderValue
prop. The function receives getter for the selected item. The element returned by this function will be rendered inside the trigger.
#
GroupsRelated options can be grouped together using SingleSelectMenu.Group
with SingleSelectMenu.Label
as a label for the group.
#
HTML Form integrationSingleSelectMenu
automatically uses hidden select part from Select Menu when it's used in the context of an HTML form.
You just need to provide name
property that will be used when submitting the form.
#
Accessibility features-
Exposed to assistive technology as a select-only combobox with a listbox popup using the WAI ARIA Listbox pattern.
-
Implements proper keyboard support and focus management practices.
-
Typeahead to allow selecting options by typing text, even without opening the listbox.
-
Browser autofill integration via a hidden native
<select>
element.
#
API Reference#
SingleSelectMenuProp | Type | Default |
---|---|---|
value | string | No default value |
defaultValue | string | No default value |
onValueChange | function | No default value |
isOpen | boolean | false |
defaultIsOpen | boolean | No default value |
onIsOpenChange | function | No default value |
size | enum | medium |
isDisabled | boolean | false |
isRequired | boolean | No default value |
validationStatus | enum | No default value |
name | string | No default value |
autoComplete | string | No default value |
#
SingleSelectMenu.TriggerProp | Type | Default |
---|---|---|
as | enum | div |
css | StitchesCss | No default value |
startElement | React.ReactElement | No default value |
endElement | React.ReactElement | No default value |
renderValue | function | No default value |
#
SingleSelectMenu.ContentProp | Type | Default |
---|---|---|
css | StitchesCss | No default value |
placement | enum | "bottom" |
anchorOffset | number | 4 |
onExitComplete | function | () => void |
#
SingleSelectMenu.ClearProp | Type | Default |
---|---|---|
css | StitchesCss | No default value |
label * | string | No default value |
#
SingleSelectMenu.ItemProp | Type | Default |
---|---|---|
as | enum | div |
css | StitchesCss | No default value |
value * | string | No default value |
isDisabled | boolean | No default value |
textValue | string | No default value |
startElement | React.ReactElement | No default value |
endElement | React.ReactElement | No default value |
#
SingleSelectMenu.ItemTextProp | Type | Default |
---|---|---|
as | enum | span |
#
SingleSelectMenu.ItemIndicatorProp | Type | Default |
---|---|---|
as | enum | div |
css | StitchesCss | No default value |
#
SingleSelectMenu.GroupProp | Type | Default |
---|---|---|
as | enum | div |
css | StitchesCss | No default value |
#
SingleSelectMenu.LabelProp | Type | Default |
---|---|---|
as | enum | div |
css | StitchesCss | No default value |
#
SingleSelectMenu.SeparatorProp | Type | Default |
---|---|---|
as | enum | div |
css | StitchesCss | No default value |