Skip to main content

A dropdown for choosing a predefined value, or several.

Place the options inside list, which carries the listbox semantics, focus and scrolling. content wraps it and is announced as a dialog with the dialog popup type. The styled ui:select.content combines positioner and content in one part, so you nest ui:select.list in it yourself:

<ui:select.content>
    <ui:select.list>
        <ui:select.item>...</ui:select.item>
    </ui:select.list>
</ui:select.content>
<primitives:select.root>
    <primitives:select.label />
    <primitives:select.control>
        <primitives:select.trigger>
            <primitives:select.valueText />
            <primitives:select.indicator />
        </primitives:select.trigger>
        <primitives:select.clearTrigger />
    </primitives:select.control>
    <primitives:select.positioner>
        <primitives:select.content>
            <primitives:select.list>
                <primitives:select.item>
                    <primitives:select.itemText />
                    <primitives:select.itemIndicator />
                </primitives:select.item>
                <primitives:select.itemGroup>
                    <primitives:select.itemGroupLabel />
                </primitives:select.itemGroup>
            </primitives:select.list>
        </primitives:select.content>
    </primitives:select.positioner>
    <primitives:select.hiddenSelect />
</primitives:select.root>
typo3 ui:add select

Read more about installing Components and Primitives.

Pass defaultValue as a list to preselect an item. The demo opens with Banana selected.

Set multiple="{true}" to select several items.

Set disabled: true on an item of the collection to make it unselectable.

Set groupByKey on ui:listCollection to group the items, here by their type, and render an itemGroup with its label per group.

Wrap the select in ui:field.root so it takes the field's name, required and invalid state. The demo is a country select for a shipping address.

Set popupType="{f:constant(name: 'Jramke\FluidPrimitives\Enum\PopupType::Dialog')}" when the popup holds more than the list. content is then announced as a dialog, list stays the listbox, and you place the other widgets next to the list inside content. In the demo, tabs narrow the produce down to fruits or vegetables.

The label of the clear button ships in the language file and follows the site language. Pass translations to override it for one select.

<ui:select.root
    collection="{countries}"
    translations="{
        clearTriggerLabel: f:translate(key: 'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:select.clear')
    }"
>
    ...
</ui:select.root>

A screen reader announces the highlighted item through a live region, and the texts ship in the language file too. itemAnnouncement sets that text and itemAnnouncementSelected the one for the selected item, both with %label% and %value% placeholders, e.g. itemAnnouncementSelected: '%label%, ausgewählt'. A client script passes itemAnnouncement as a function of { value, label, selected } instead.

The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.

Provides shared select state and wraps all related parts. Renders a <div> element.

NameDescriptionRequiredDefault
collectionDomain\Dto\ListCollection
The item collection.
Yes
-
namestring
The `name` attribute of the underlying select. Inherited from a surrounding field when available.
No
-
formstring
The associate form of the underlying select.
No
-
disabledboolean
Whether the select is disabled. Inherited from a surrounding field when available.
No
-
invalidboolean
Whether the select is invalid. Inherited from a surrounding field when available.
No
-
readOnlyboolean
Whether the select is read-only. Inherited from a surrounding field when available.
No
-
requiredboolean
Whether the select is required. Inherited from a surrounding field when available.
No
-
closeOnSelectboolean
Whether the select should close after an item is selected.
No
true
positioningarray
The positioning options of the menu.
No
{
    "placement": "bottom-start",
    "gutter": 8
}
defaultValuestring|string[]
The initial default value of the select when rendered. Use when you don't need to control the value of the select. Inherited from a surrounding field when available.
No
-
defaultHighlightedValuestring
The initial value of the highlighted item when opened. Use when you don't need to control the highlighted value of the select.
No
-
loopFocusboolean
Whether to loop the keyboard navigation through the options.
No
false
multipleboolean
Whether to allow multiple selection.
No
-
defaultOpenboolean
Whether the select's open state is controlled by the user.
No
false
popupTypeEnum\PopupType
The kind of popup the select's content is: `listbox` for a regular select, `dialog` when it holds other interactive content.
No
Listbox
deselectableboolean
Whether the value can be cleared by clicking the selected item.
No
-
translationsarray
Localized select labels. `itemAnnouncement` (the live region text of a highlighted item) and `itemAnnouncementSelected` (the same for a selected item) take `%label%` and `%value%` placeholders, and `itemAnnouncement` is a function of the item in a client script. Use `f:translate` for per-template localization overrides when needed.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-root<uid>
data-invalidPresent when invalid
data-readonlyPresent when read-only

Labels the select. Renders a <label> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-label<uid>
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only
data-requiredPresent when required

Groups the trigger and optional clear button. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-control<uid>
data-state"open" | "closed"
data-focusPresent when focused
data-disabledPresent when disabled
data-invalidPresent when invalid

Opens and closes the select menu. Renders a <button> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-trigger<uid>
data-state"open" | "closed"
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only
data-placementThe placement of the trigger
data-align-with-trigger
data-sideThe side of the trigger that the trigger is positioned on
data-placeholder-shownPresent when placeholder is shown

Displays the selected value or placeholder text. Renders a <span> element.

NameDescriptionRequiredDefault
placeholderstring
The placeholder text to render when no value is selected.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-value-text<uid>
data-disabledPresent when disabled
data-invalidPresent when invalid
data-focusPresent when focused

Displays a decorative indicator for the trigger. Renders a <span> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-indicator<uid>
data-state"open" | "closed"
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only

Clears the current selection. Renders a <button> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-clear-trigger<uid>
data-invalidPresent when invalid

Positions the floating select content. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-positioner<uid>
data-nestedPresent when the positioner is nested within another {{widget}}
data-has-nestedPresent when the positioner has nested {{widget}}s

The popup surface, positioned by positioner. Holds the list and, with popupTypedialog, other widgets next to it. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-content<uid>
data-state"open" | "closed"
data-placementThe placement of the content
data-align-with-trigger
data-sideThe side of the trigger that the content is positioned on
data-nestedlistbox
data-has-nestedlistbox

The listbox inside content that holds the options - it takes focus, scrolls and tracks the active option. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-list<uid>
data-activedescendantThe id the active descendant of the list

Groups related options together. Renders a <div> element.

NameDescriptionRequiredDefault
valuestring
The value identifier of the item group.
Yes
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-item-group<uid>
data-disabledPresent when disabled

Labels a group of related options. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Represents a selectable option. Renders a <div> element.

NameDescriptionRequiredDefault
itemmixed
The item to render.
Yes
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-item<uid>
data-valueThe value of the item
data-state"checked" | "unchecked"
data-highlightedPresent when highlighted
data-disabledPresent when disabled

Displays the text content of an option. Renders a <span> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-item-text<uid>
data-state"checked" | "unchecked"
data-disabledPresent when disabled
data-highlightedPresent when highlighted

Displays the selected-state indicator for an option. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-select-item-indicator<uid>
data-state"checked" | "unchecked"

Provides the native <select> element for form submission. Renders a <select> element, with the empty-value input that submits '' while nothing is selected in front of it.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-
NameTypeDescription
scrollArrowVisibility"none" | "top" | "bottom" | "both"Which scroll arrows should be visible based on the content's scroll position. - `"none"`: content fits, no scrolling needed - `"top"`: scrolled past the top (top arrow visible) - `"bottom"`: more content below (bottom arrow visible) - `"both"`: scrolled somewhere in the middle (both arrows visible)
focusedbooleanWhether the select is focused
openbooleanWhether the select is open
emptybooleanWhether the select value is empty
highlightedValuestring | nullThe value of the highlighted item
highlightedItemV | nullThe highlighted item
setHighlightValue(value: string) => voidFunction to highlight a value
clearHighlightValueVoidFunctionFunction to clear the highlighted value
selectedItemsV[]The selected items
hasSelectedItemsbooleanWhether there's a selected option
valuestring[]The selected item keys
valueAsStringstringThe string representation of the selected items
selectValue(value: string) => voidFunction to select a value
selectAllVoidFunctionFunction to select all values
setValue(value: string[]) => voidFunction to set the value of the select
clearValue(value?: string) => voidFunction to clear the value of the select. If a value is provided, it will only clear that value, otherwise, it will clear all values.
focusVoidFunctionFunction to focus on the select input
getItemState(props: ItemProps) => ItemStateReturns the state of a select item
setOpen(open: boolean) => voidFunction to open or close the select
collectionListCollection<V>Function to toggle the select
reposition(options?: Partial<PositioningOptions>) => voidFunction to set the positioning options of the select
multiplebooleanWhether the select allows multiple selections
disabledbooleanWhether the select is disabled
getRootState() => RootStateReturns the state of the root
getTriggerState() => TriggerStateReturns the state of the trigger
getContentState() => ContentStateReturns the state of the content
KeyDescription
SpaceWhen focus is on trigger, opens the select and focuses the first selected item.
When focus is on the content, selects the highlighted item.
EnterWhen focus is on trigger, opens the select and focuses the first selected item.
When focus is on content, selects the focused item.
ArrowDownWhen focus is on trigger, opens the select.
When focus is on content, moves focus to the next item.
ArrowUpWhen focus is on trigger, opens the select.
When focus is on content, moves focus to the previous item.
EscCloses the select and moves focus to trigger.
A-Za-zWhen focus is on trigger, selects the item whose label starts with the typed character.
When focus is on the listbox, moves focus to the next item with a label that starts with the typed character.