Adding "clearable" to select component
This release introduces a new clearable feature for the Select component. It provides a way to clear the selected options (single and multiple) and improves the overall user experience.
This feature can be enabled by adding the clearable
attribute to the select component:
<.select
field={f[:country]}
placeholder="Select a country"
label="Country"
options={[{"Germany", "de"}, {"Japan", "jp"}, {"Australia", "au"}]}
clearable
/>
The clearable feature includes the following behaviors:
- Clear Icon: A "x" icon is displayed when there are selected options - clicking it clears all selections in both single and multiple select modes
- Option Unselect: Single option selects can now be unselected by clicking the selected option
- Backspace Key: Pressing backspace when the select is focused will clear all selections, similarly to clicking the clear icon
When unselecting a single option, an empty option (<option value="">
) is selected under the hood, sending an empty string in the form data. This behavior matches how multiple select handles empty states by sending the ([""]
) array.
Additionally, keyboard navigation has been improved. When opening the select using keyboard navigation, it will now start from the selected option instead of defaulting to the first or last position. This makes navigation more intuitive, especially with long option lists.
Bug Fixes
- Fixed: Stacked dialogs (sheet and modal) no longer lose their z-index reference when receiving LiveView patches