This documentation is under construction. Pages can be missing or change at any time. Follow it on GitHub.

Skip to content

Select

A common form component for choosing a predefined value in a dropdown menu.

Examples#

Formatting the value#

SelectValue renders the label of the selected item: its SelectItemText, not its raw value.

To show more than a text, see the object values.

Labeling a select#

Use SelectLabel to provide a visible label for the select trigger. SelectLabel renders a <div>, so clicking it focuses the select trigger without opening the popup.

Placeholder values#

To show a placeholder value, use the placeholder prop on SelectValue.

Multiple selection#

Add the multiple prop to the Select component to allow multiple selections. The template of SelectValue gives the text of two values or more.

Object values#

Select items can show more than a text. With markup, SelectValue shows a copy of the markup of the selected item text.

Grouped#

Organize related options with SelectGroup and SelectGroupLabel to add section headings inside the popup.

API reference#

Import the components of the family:

use Phem\Ui\Select;
use function Phem\Ui\{SelectLabel, SelectTrigger, SelectValue, SelectIcon, SelectPopup, SelectList, SelectScrollUpArrow, SelectScrollDownArrow, SelectItem, SelectItemIndicator, SelectItemText, SelectGroup, SelectGroupLabel, SelectSeparator};

Select#

A button that opens a list of options: Base UI Select.Root, on the phem-select controller.

defaultValue is the value of the selected item (a list with multiple). With a name (or phem:bind), a hidden input keeps the value for the form. By default the popup goes over the trigger (alignItemWithTrigger). Give an id to label the trigger with its SelectLabel.

PropTypeDefault
defaultValuestring|array|nullnull
multipleboolfalse
name?stringnull
id?stringnull
alignItemWithTriggerbooltrue
modalbooltrue
disabledboolfalse
readOnlyboolfalse
requiredboolfalse
loopFocusboolfalse
side'top' | 'bottom' | 'left' | 'right' | 'inline-start' | 'inline-end'Side::Bottom
align'start' | 'center' | 'end'Align::Start
sideOffsetint0
value?Boundnull
children?Htmlnull
...attrsarray[]

SelectLabel#

The label of the select. It names the trigger (aria-labelledby).

PropTypeDefault
children?Htmlnull
...restmixed—

SelectTrigger#

The button that opens the popup. In a Toolbar, it is an item of the toolbar.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectValue#

The label of the selected item, or the placeholder. The controller writes its text. template gives the text of two values or more ({first} (+{others} more)), and markup shows a copy of the markup of the item text.

PropTypeDefault
placeholder?stringnull
template?stringnull
markupboolfalse
...restmixed—

SelectItem#

An option. value is its value.

PropTypeDefault
value (required)string—
disabledboolfalse
children?Htmlnull
...restmixed—

SelectIcon#

The icon of the trigger, a caret by default.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectPopup#

The box of the select, with the list of the items. The controller places it next to the trigger.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectList#

The list of the items in the popup (listbox). It scrolls when the items are higher than the screen.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectScrollUpArrow#

An arrow at the top of the popup: a hover scrolls the list up.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectScrollDownArrow#

An arrow at the bottom of the popup: a hover scrolls the list down.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectItemIndicator#

The check of the selected item.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectItemText#

The text of an item: the label that the value part shows.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectGroup#

A group of items of the list, with a SelectGroupLabel.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectGroupLabel#

The label of a SelectGroup.

PropTypeDefault
children?Htmlnull
...restmixed—

SelectSeparator#

A line between two items or two groups of the list.

PropTypeDefault
...restmixed—

The source of the examples: examples/ui/Select.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close