Select
A common form component for choosing a predefined value in a dropdown menu.
Features
- Support for single and multiple selection
- Typeahead to allow focusing items by typing text
- Keyboard navigation support including arrow keys, home/end
- Supports disabled items and groups
- Works with Field component for form integration
- Supports custom positioning
Installation
typo3 ui:add select
Please copy the files manually from GitHub into your project.
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.
| Name | Description | Required | Default |
|---|---|---|---|
collection | Domain\Model\ListCollectionThe item collection. | Yes | - |
name | stringThe `name` attribute of the underlying select. Inherited from a surrounding field when available. | No | - |
form | stringThe associate form of the underlying select. | No | - |
disabled | booleanWhether the select is disabled. Inherited from a surrounding field when available. | No | - |
invalid | booleanWhether the select is invalid. Inherited from a surrounding field when available. | No | - |
readOnly | booleanWhether the select is read-only. Inherited from a surrounding field when available. | No | - |
required | booleanWhether the select is required. Inherited from a surrounding field when available. | No | - |
closeOnSelect | booleanWhether the select should close after an item is selected. | No | true |
positioning | arrayThe positioning options of the menu. | No | {
"placement": "bottom-start",
"gutter": 8
} |
defaultValue | mixedThe 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 | - |
defaultHighlightedValue | stringThe initial value of the highlighted item when opened. Use when you don't need to control the highlighted value of the select. | No | - |
loopFocus | booleanWhether to loop the keyboard navigation through the options. | No | false |
multiple | booleanWhether to allow multiple selection. | No | - |
defaultOpen | booleanWhether the select's open state is controlled by the user. | No | - |
composite | booleanWhether the select is composed with other composite widgets like tabs or combobox. | No | true |
deselectable | booleanWhether the value can be cleared by clicking the selected item. | No | - |
translations | arrayLocalized select labels. Set entries to `` to omit the corresponding `aria-label`. Use `f:translate` for per-template localization overrides when needed. | No | - |
select.label
Labels the select. Renders a <label> element.
select.control
Groups the trigger and optional clear button. Renders a <div> element.
select.trigger
Opens and closes the select menu. Renders a <button> element.
select.valueText
Displays the selected value or placeholder text. Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
placeholder | stringThe placeholder text to render when no value is selected. | No | - |
select.indicator
Displays a decorative indicator for the trigger. Renders a <span> element.
select.clearTrigger
Clears the current selection. Renders a <button> element.
select.positioner
Positions the floating select content. Renders a <div> element.
select.content
Contains the selectable options. Renders a <div> element.
select.itemGroup
Groups related options together. Renders a <div> element.
select.itemGroupLabel
Labels a group of related options. Renders a <div> element.
select.item
Represents a selectable option. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
item | mixedThe item to render. | Yes | - |
select.itemText
Displays the text content of an option. Renders a <span> element.
select.itemIndicator
Displays the selected-state indicator for an option. Renders a <div> element.
select.hiddenSelect
Provides the native <select> element for form submission. Renders a <select> element.
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>