A select component powered by a custom HTML element <select-element>.
This component allows for a dropdown selection with optional grouping. The underlying custom element handles popover behavior, keyboard navigation, and accessibility.
An attribute for configuring the SelectElement component.
You can use attributes to set options, handle selection, customize appearance, and more.
SelectElement.view "Choose a planet"
[ SelectElement.optionItems myOptions
, SelectElement.selectedValue (Just Earth)
, SelectElement.onSelect SelectPlanet
, SelectElement.label "Planets"
, SelectElement.disabled False
]Represents an item in the select dropdown.
You can use Item for a single option, or Group to group related options under a label.
SelectElement.Item
{ content = Html.Styled.text "Earth"
, triggerLabel = "Earth"
, value = Earth
}
SelectElement.Group "Gas Giants"
[ { content = Html.Styled.text "Jupiter"
, triggerLabel = "Jupiter"
, value = Jupiter
}
, { content = Html.Styled.text "Saturn"
, triggerLabel = "Saturn"
, value = Saturn
}
]Changes from V1:
- Implemented Elm-first styling
- Removed global CSS dependencies
- Used InputLabelInternal for label rendering
- Used InputErrorAndGuidanceInternal for error and guidance rendering
- Added scroll indicatorsRepresents a single selectable option.
content: The HTML to display in the dropdown.triggerLabel: The plain text label to show in the trigger button when selected.value: The value associated with this option.Example:
{ content = Html.Styled.text "Earth"
, triggerLabel = "Earth"
, value = Earth
}Defines the list of options and option groups to display in the select dropdown.
Sets the currently selected value.
The message to send when an option is selected. It receives the newly selected value.
The HTML ID for the trigger button.
This ID is used by the select-element to associate with its trigger.
Defaults to "select-element-trigger-default".
The HTML ID for the select-element popover.
Defaults to "select-element-popover-default".
Sets the accessible label for the select trigger.
This is important for screen readers. Use hideLabel to control visual display.
If True, the label provided via the label attribute will be visually hidden
(but still available to assistive technologies). Defaults to False.
Puts the select component in a loading state. This disables interaction and changes the visual appearance.
Adds an SVG icon to the trigger button. The icon will be placed before the text.
A predicate function to determine if an individual option should be disabled. Disabled options are not selectable and visually distinct.
Sets an error message to be displayed below the component. If set, it overrides any guidance message.
Sets a guidance message to be displayed below the component. This message is not shown if an error message is present.
Custom CSS styles for the main container div wrapping the component.
If True, removes the default top margin from the component container.
A function to convert your custom value type to a String.
This is necessary for setting data-value attributes on options and for
generating unique option IDs.
A function to convert a String (from the select-change event detail)
back to your custom value type.
Add custom HTML attributes to the trigger button.
Add custom HTML attributes to the select-element (popover).
Renders the SelectElement component. The
defaultTriggerTextis used as the content of the trigger button if noselectedValueprovides a label, or if nolabelattribute is set.