Select
A Select component to select values from a list of options.
Examples
Basic
Basic Select
usage examples
Search Field
Use the searchable
prop to search the options while the Select is expanded. By default it will search the label for an exact match, but a searchFunction
can be passed for customizing the search.
Multiple Select
Show more than one selection using multiple
mode. Multiple mode is searchable as well.
Sizes
The height of the input field for the select defaults to 32px. If size is set to large, the height will be 40px, and if set to small, 24px.
Custom Selection Display
Custom content can be displayed for each option inside the dropdown.
Option Groups
Options can be organized in groups within the dropdown.
Remote Search
An example of using the search
event to fetch options from an external source.
Custom Dropdown Content
The dropdown can be customized by adding content inside the Select tag.
Hide Already Selected
Hide already selected options in the dropdown.
Borderless
The select can be rendered without borders so it looks like text rather than an input.
API
Select Attributes
Property | Description | Type | Default |
---|---|---|---|
value | The current value of the select. Can be used for 2 way binding: `bind:value`. | String|Array | - |
style | Style string or style object (e.x. `style={{ fontSize: 18 }}`) for the Select wrapper. | String|Object | - |
class | Class name or class object (e.x. `class={{ 'abc':true }}`) for the Select wrapper. | String|Object | - |
dropdownClass | Class name or class object (e.x. `class={{ 'abc':true }}`) for the dropdown. | String|Object | - |
dropdownStyle | Style string or style object (e.x. `style={{ fontSize: 18 }}`) for the dropdown. | String|Object | - |
dropdownHeight | Max height of the dropdown. Overflow will be scrollable | String | 256px |
disabled | Whether or not the Select is interactive. | Boolean | false |
loading | Whether the loading spinner should show. | Boolean | false |
clearable | Whether the close icon will show when the Select is hovered on. When clicked it will clear the value. | Boolean | false |
autoClearSearchValue | Whether the current search will be cleared on selecting an item. Only applies `when` mode is set to `multiple` or `tags`. | Boolean | true |
placeholder | The placeholder to show if there is no value. | String | - |
searchable | Whether the select has a search input in single mode to filter the options displayed. | Boolean | false |
searchFunction | Custom search function used together with the `searchable` prop. It takes the `searchInput` and the `option` as arguments and will be used to search in place of the default label only search. If the function returns `true` for a given option, it wil be displayed. | Function | function that searches for a matching label |
mode | The select mode. Allowed values are `single`, `multiple`, and `tags`. See the examples above for details. | String | single |
size | The size of the Select input. Valid values are `small`, `default`, and `large`. | String | default |
showEmptyMessage | Whether to show the "No options" message in the dropdown when there are no options available. | Boolean | true |
borderless | Makes the Select input render with no borders so it looks like plain text with chevron down icon. | Boolean | false |
tagProps | A function used in `tags` mode that will render tags with custom props. It takes the option as an argument and should return tag props. It can also include onClose and onClick functions. | Function | - |
maxTagDisplayCount | The maximum amount of tags to show in the input when in `multiple` or `tags` mode. | Number | - |
maxTagTextLength | The maximum amount of characters for a display tag in `multiple` or `tags` mode. An ellipses will be shown if there are more characters. | Number | - |
showArrow | Whether to show the drop-down arrow. | Boolean | true |
suffixIcon | Custom icon in place of the arrow in the select input. | SvelteComponent | DownOutlined |
clearIcon | Clear icon to use when the Select is clearable and the user hovers over the select. | SvelteComponent | CloseCircleFilled |
defaultOpen | Initial open state of the dropdown. | Boolean | false |
open | Controlled open state of the dropdown. | Boolean | - |
Option Attributes
Property | Description | Type | Default |
---|---|---|---|
value | Value of the option. | String | - |
label | Label of the option | String | - |
disabled | Disabled state of the option | Boolean | false |
OptionGroup Attributes
Property | Description | Type | Default |
---|---|---|---|
label | The OptionGroup label | String | - |
Select Events
Name | Description |
---|---|
change | The Select's value changed. |
blur | The user clicked away from the Select. |
focus | The user focused the Select. |
search | The user typed a character into the search input. |
dropdownvisiblechange | The dropdown is opened or closed. |
Slots
Name | Description | Component |
---|---|---|
default (no name needed) | The default slot for Select expects options, but any custom content can be added in there as well together with the options. See the above "Custom Dropdown Content" section for an example. | Select |
no-options | Custom content to display when there are no options. Generally used for when search results come up empty. | Select |
default (no name needed) | Custom content to display for the Option inside the dropdown. If no content is put in the default slot, the option will render the label. See the above "Custom Selection Display" section for an example. | Option |