Skip to main content

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

Features

Installation

typo3 ui:add select

Read more about installing Components and Primitives.

Examples

Default Value

Set an initial selected value.

Multiple Selection

Allow selecting multiple items.

Disabled Items

Disable specific items in the list.

With Item Groups

Organize items into logical groups.

With Form Field

Use with the Field component for form validation.

Localization

Default clear trigger labels are shipped via XLF and follow the current Site Language. For per-template overrides, pass translated strings through the translations prop. Set clearTriggerLabel to {false} or an empty string to omit the aria-label.

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

API Reference

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.

select.root

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
}
defaultValuemixed
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
compositeboolean
Whether the select is composed with other composite widgets like tabs or combobox.
No
true
deselectableboolean
Whether the value can be cleared by clicking the selected item.
No
-
translationsarray
Localized select labels. Set entries to `` to omit the corresponding `aria-label`. Use `f:translate` for per-template localization overrides when needed.
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
[]
controlledboolean
If true, the component is meant to be initialized manually inside another component
No
false
classstring
The CSS class(es) to be applied to the component.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partroot
data-invalidPresent when invalid
data-readonlyPresent when read-only

select.label

Labels the select. Renders a <label> element.

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partlabel
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only
data-requiredPresent when required

select.control

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partcontrol
data-state"open" | "closed"
data-focusPresent when focused
data-disabledPresent when disabled
data-invalidPresent when invalid

select.trigger

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-parttrigger
data-state"open" | "closed"
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only
data-placementThe placement of the trigger
data-sideThe side of the trigger that the trigger is positioned on
data-placeholder-shownPresent when placeholder is shown

select.valueText

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

NameDescriptionRequiredDefault
placeholderstring
The placeholder text to render when no value is selected.
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partvalue-text
data-disabledPresent when disabled
data-invalidPresent when invalid
data-focusPresent when focused

select.indicator

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partindicator
data-state"open" | "closed"
data-disabledPresent when disabled
data-invalidPresent when invalid
data-readonlyPresent when read-only

select.clearTrigger

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partclear-trigger
data-invalidPresent when invalid

select.positioner

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

select.content

Contains the selectable options. Renders a <div> element.

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partcontent
data-state"open" | "closed"
data-nestedlistbox
data-has-nestedlistbox
data-placementThe placement of the content
data-sideThe side of the trigger that the content is positioned on
data-activedescendantThe id the active descendant of the content

select.itemGroup

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

NameDescriptionRequiredDefault
valuestring
The value identifier of the item group.
Yes
-
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partitem-group
data-disabledPresent when disabled

select.itemGroupLabel

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

select.item

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

NameDescriptionRequiredDefault
itemmixed
The item to render.
Yes
-
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partitem
data-valueThe value of the item
data-state"checked" | "unchecked"
data-highlightedPresent when highlighted
data-disabledPresent when disabled

select.itemText

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partitem-text
data-state"checked" | "unchecked"
data-disabledPresent when disabled
data-highlightedPresent when highlighted

select.itemIndicator

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

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Rendered data attributes

AttributeDescription
data-scopeselect
data-partitem-indicator
data-state"checked" | "unchecked"

select.hiddenSelect

Provides the native <select> element for form submission. Renders a <select> element.

NameDescriptionRequiredDefault
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
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]

Machine JavaScript API

NameTypeDescription
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

Accessibility

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.

Anatomy

<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.item>
                <primitives:select.itemText />
                <primitives:select.itemIndicator />
            </primitives:select.item>
            <primitives:select.itemGroup>
                <primitives:select.itemGroupLabel />
            </primitives:select.itemGroup>
        </primitives:select.content>
    </primitives:select.positioner>
    <primitives:select.hiddenSelect />
</primitives:select.root>