Select
<afp-select>
A select component that allows users to choose one or more options from a dropdown list.
Examples #
Shape #
Use the shape attribute to change a select's shape.
Sizes #
Use the size attribute to change a select's size.
Label #
Use the label attribute or slot to set the Select's label.
Tooltip #
Use the tooltip attribute to show the label's text as a tooltip when hovering on the label.
Hint #
Use the hint attribute to provide additional information about the select.
Placeholder #
Use the placeholder attribute to set a placeholder text for the select.
Search #
Use the search attribute to enable a search field to quickly filter the options by text.
Value #
The value attribute can be used to set the initial selected value of the select.
Clearable #
Use the clearable attribute to add a clear button to the select.
Multiple #
Use the multiple and maxVisible attributes to allow multiple selections in the select.
Disabled #
Use the disabled attribute to disable the select.
Invalid #
Use the invalid attribute to indicate the select is in an invalid state.
Customization #
Use the --afp-select-max-height CSS variable to set a custom maximum height for the dropdown.
Classic Coffees
Specialty & Iced Coffees
Notes #
The Select component is built on top of the Popover component and therefore inherits many of its configuration options.
This includes properties like placement, offset, strategy, and duration, which control how and where the dropdown appears, how far it’s positioned from its trigger, the positioning strategy (absolute or fixed), and the transition timing for showing or hiding it.
For a detailed explanation of these options, see the Popover documentation.
Properties
Learn more about properties.
| Name | Description | Reflects | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name
|
The name attribute to use for the underlying select input element.
Type
string
|
|||||||||||||||||||||||||||
value
|
The current value of the select. Can be a string or an array of strings for multiple select.
Type
string | string[] | null
Default
null |
|||||||||||||||||||||||||||
placeholder
|
Placeholder text displayed when no option is selected.
Type
string
|
|||||||||||||||||||||||||||
multiple
|
Indicates whether multiple options can be selected.
Type
boolean
Default
false |
|
||||||||||||||||||||||||||
open
|
Indicates whether the select dropdown is open.
Type
boolean
Default
false |
|||||||||||||||||||||||||||
invalid
|
Validation footer property of select
Type
string
|
|
||||||||||||||||||||||||||
hint
|
Hint footer property of select
Type
string
|
|
||||||||||||||||||||||||||
clearable
|
Indicates whether the select can be cleared.
Type
boolean
Default
false |
|
||||||||||||||||||||||||||
maxVisible
maxvisible
|
Maximum number of selected items shown in trigger (only for multiple).
If null → unlimited.
Type
number
Default
3 |
|||||||||||||||||||||||||||
tooltip
|
show label tooltip by hover
Type
boolean
|
|
||||||||||||||||||||||||||
label
|
label header property of select
Type
string
|
|||||||||||||||||||||||||||
size
|
The size of the select component.
Type
AfpSize
Default
AfpSize.MEDIUM |
|
||||||||||||||||||||||||||
shape
|
The shape of the select component.
Type
AfpShape
Default
AfpShape.ROUNDED |
|
||||||||||||||||||||||||||
disabled
|
Indicates whether the select is disabled.
Type
boolean
Default
false |
|
||||||||||||||||||||||||||
strategy
|
The positioning strategy to use for the popover.
Type
AfpStrategy
Default
AfpStrategy.ABSOLUTE |
|||||||||||||||||||||||||||
offset
|
The offset for the popover positioning.
Type
AfpOffset
Default
{ mainAxis: 4, crossAxis: 0, alignmentAxis: 0 } |
|
||||||||||||||||||||||||||
duration
|
The duration of the popover show/hide animation in milliseconds.
Type
number
Default
150 |
|||||||||||||||||||||||||||
hideLabel
hidelabel
|
hides the label visually
Type
boolean
|
|
||||||||||||||||||||||||||
placement
|
The placement preferences for the popover.
Type
AfpPlacement
Default
[AfpPlacement.BOTTOM, AfpPlacement.TOP] |
|
||||||||||||||||||||||||||
search
|
enables an input field to search fot options
Type
boolean
|
|
Methods
Learn more about using methods.
| Name | Description | Arguments |
|---|---|---|
show
|
Shows the select dropdown.
|
fromKeyboard<boolean>
— Indicates if the action was triggered by keyboard.
|
hide
|
Hides the select dropdown.
|
- |
Events
Learn more about events.
| Name | Return | Description |
|---|---|---|
afp-value-changed
|
string | string[] | null
|
Emitted when the value of the select changes.
|
afp-select
|
string | string[] | null
|
Emitted when an option is selected.
|
afp-clear
|
void
|
Emitted when the select value is cleared.
|
afp-show
|
void
|
Emitted when the dropdown is shown.
|
afp-hide
|
void
|
Emitted when the dropdown is hidden.
|
afp-after-show
|
void
|
Emitted after the dropdown has been shown.
|
afp-after-hide
|
void
|
Emitted after the dropdown has been hidden.
|
Slots
Learn more about slots.
| Name | Description |
|---|---|
default
|
The default slot for the select options (afp-option elements).
|
label
|
The slot for the label content.
|
content-prefix
|
The slot for content to appear before the selected value(s) in the trigger.
|
content-suffix
|
The slot for content to appear after the selected value(s) in the trigger.
|
actions
|
The slot for additional action elements in the trigger.
|
dropdown-caret
|
The slot for a custom dropdown caret icon.
|
clear-icon
|
The slot for a custom clear icon.
|
Internationalization
Learn more about internationalization.
| Key | Description |
|---|---|
select.clear-button.aria-label
|
The default `aria-label` text for the clear button
|
select.search-field.placeholder
|
The default placeholder text for the search field
|
search-field.aria-label
|
The default `aria-label` text for the search field
|
CSS Parts
Learn more about CSS Parts.
| Name | Description | Selector |
|---|---|---|
wrapper
|
The component's outer wrapper.
|
::part(wrapper)
|
label-base
|
The label wrapper.
|
::part(label-base)
|
label
|
The label element.
|
::part(label)
|
popover
|
The popover element.
|
::part(popover)
|
panel
|
The dropdown panel.
|
::part(panel)
|
trigger
|
The trigger element.
|
::part(trigger)
|
content
|
The trigger content container.
|
::part(content)
|
actions
|
The trigger actions container.
|
::part(actions)
|
clear-button
|
The clear button.
|
::part(clear-button)
|
clear-icon
|
The clear button icon.
|
::part(clear-icon)
|
dropdown-caret
|
The dropdown caret icon.
|
::part(dropdown-caret)
|
invalid-base
|
The invalid message wrapper.
|
::part(invalid-base)
|
invalid
|
The invalid message text.
|
::part(invalid)
|
hint-base
|
The hint message wrapper.
|
::part(hint-base)
|
hint
|
The hint message text.
|
::part(hint)
|
search-icon
|
The search icon in the search field.
|
::part(search-icon)
|
afp-select-search-input
|
The search input field.
|
::part(afp-select-search-input)
|
placeholder
|
The placeholder text in the trigger when no option is selected.
|
::part(placeholder)
|
placeholder-multiple
|
The placeholder text in the trigger when no option is selected in multiple select mode.
|
::part(placeholder-multiple)
|
CSS Custom Properties
| Name | Description | Default |
|---|---|---|
--afp-select-max-height
|
The maximum height of the select dropdown panel.
|
10rem
|
--afp-select-scale
|
The scale factor for the select component.
|
0.97
|
--afp-input-error-border-color
|
The border color of the select trigger in the invalid/error state.
|
--afp-color-error-border-quiet
|
--afp-select-multiple-padding
|
The padding of the trigger when multiple options are selected.
|
0 var(--afp-space-m) 0 var(--afp-space-2xs)
|
--afp-select-content-prefix-padding
|
The padding for the content prefix slot in the trigger.
|
0
|
--afp-select-content-suffix-padding
|
The padding for the content suffix slot in the trigger.
|
0
|
Dependencies
The component automatically brings in the listed items, including any nested dependencies that may exist.
Importing
Using the bundle is the recommended method to include components. If you’d rather handle imports manually, you can use the code examples below.
import '@afp-design-system/core/dist/components/select/select.js';