Select Ready
Select lets user choose one option from an options menu. Consider using select when you have 6 or more options. Select component supports any content type.
Examples #
<duet-select id="duet-select_default_select" label="Kaupunki" placeholder="Valitse"></duet-select>
<script>
(function(){
// Save a reference to the above select component
var select = document.querySelector("#duet-select_default_select")
// Set select menu items and their values
select.items = [
{ label: "Helsinki", value: "1" },
{ label: "Tampere", value: "2" },
{ label: "Vantaa", value: "3" },
{ label: "Espoo", value: "4" },
]
// Listen for change events in the select
select.addEventListener("duetChange", function (e) {
console.log("Change event detected in select:", e.detail)
})
}())
</script>
<duet-select id="duet-select_default_select_with_aria_labels" label="Kaupunki" placeholder="Valitse"></duet-select>
<script>
(function(){
// Save a reference to the above select component
var select = document.querySelector("#duet-select_default_select_with_aria_labels")
// Set select menu items and their values
select.items = [
{ label: "Helsinki", value: "1", ariaLabel: "Helsinki label" },
{ label: "Tampere", value: "2", ariaLabel: "Tampere label" },
{ label: "Vantaa", value: "3", ariaLabel: "Vantaa label" },
{ label: "Espoo", value: "4", ariaLabel: "Espoo label" },
]
// Listen for change events in the select
select.addEventListener("duetChange", function (e) {
console.log("Change event detected in select:", e.detail)
})
}())
</script>
<duet-select id="duet-select_preselected_value_in_select" label="Kaupunki" placeholder="Valitse" value="2"></duet-select>
<script>
(function() {
var select = document.querySelector("#duet-select_preselected_value_in_select")
select.items = [
{label: "Helsinki", value: "1"},
{label: "Tampere", value: "2"},
{label: "Vantaa", value: "3"},
{label: "Espoo", value: "4"},
]
}())
</script>
<duet-select id="duet-select_compact_select" label="Numero" label-hidden placeholder="00000" variation="compact"></duet-select>
<script>
(function(){
// Save a reference to the above select component
var select = document.querySelector("#duet-select_compact_select")
// Set select menu items and their values
select.items = [
{ label: "2", value: "2" },
{ label: "88", value: "3" },
{ label: "999", value: "4" },
{ label: "1000", value: "5" },
]
// Listen for change events in the select
select.addEventListener("duetChange", function (e) {
console.log("Change event detected in select:", e.detail)
})
}())
</script>
<duet-select id="duet-select_disabled_select" label="Kaupunki" placeholder="Valitse" disabled></duet-select>
<script>
(function() {
var select = document.querySelector("#duet-select_disabled_select")
select.items = [
{label: "Helsinki", value: "1"},
{label: "Tampere", value: "2"},
{label: "Vantaa", value: "3"},
{label: "Espoo", value: "4"},
]
}())
</script>
<duet-select
label="Kaupunki"
placeholder="Valitse"
items='[
{ "label": "Helsinki", "value": "1" },
{ "label": "Tampere", "value": "2" },
{ "label": "Vantaa", "value": "3" },
{ "label": "Espoo", "value": "4" }
]'
>
</duet-select>
Properties #
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
accessibleActiveDescendant | accessible-active-descendant | Indicates the id of a related component’s visually focused element. | string | undefined |
accessibleControls | accessible-controls | Use this prop to add an aria-controls attribute. Use the attribute to indicate the id of a component controlled by this component. | string | undefined |
accessibleDescribedBy | accessible-described-by | Indicates the id of a component that describes the input. | string | undefined |
accessibleLiveError | accessible-live-error | The aria-live attribute for the error message. When the input is validated on blur, use "off", as using "polite" or "assertive" makes the screen reader read the error message twice. When the input is validated on submit, use "polite", as "off" would leave the messages unread by screen readers. Use "assertive" only in those rare cases when "polite" would leave the error message unread by screen readers. | "assertive" | "off" | "polite" | "polite" |
accessibleOwns | accessible-owns | Indicates the id of a component owned by the select. | string | undefined |
caption | caption | Caption (underneath label) that can be set as a way of adding extra information | string | undefined |
disabled | disabled | Makes the select component disabled. This prevents users from being able to interact with the select, and conveys its inactive state to assistive technologies. | boolean | false |
echoPlaceholder | echo-placeholder | If form input field has a placeholder text, and user types anything (causing the placeholder text to disappear), settings this to true will "echo" it into the caption slot - this option will be false by default for the next few versions, but will eventually be true by default (scheduled for 4.30.0) | boolean | false |
error | error | Display the select in error state along with an error message. | string | "" |
expand | expand | Expands the input to fill 100% of the container width. | boolean | false |
identifier | identifier | Adds a unique identifier for the select. | string | undefined |
items | items | An array of items to choose from | (DuetSelectOption | DuetSelectOptionGroup)[] | string | undefined |
label | label | Label for the select. | string | "label" |
labelColor | label-color | Color of the label. | string | undefined |
labelHidden | label-hidden | Visually hide the label, but still show it to screen readers. | boolean | false |
labelWeight | label-weight | Font weight of the label. | "normal" | "semi-bold" | undefined |
margin | margin | Controls the margin of the component. | "auto" | "none" | "auto" |
name | name | Name of the select. | string | undefined |
placeholder | placeholder | Hint text to display. | string | "" |
required | required | Set whether the input is required or not. Please note that this is necessary for accessible inputs when the user is required to fill them. When using this property you need to also set “novalidate” attribute to your form element to prevent browser from displaying its own validation errors. | boolean | false |
role | role | Defines a specific role attribute for the select. | string | undefined |
theme | theme | Theme of the select. | "" | "default" | "turva" | "" |
tooltip | tooltip | Tooltip to display next to the label of the input. | string | "" |
tooltipDirection | tooltip-direction | With direction setting you can force the tooltip to always open towards left or right instead of automatically determining the direction. | "auto" | "left" | "right" | "auto" |
value | value | The selected value of the select | string | undefined |
variation | variation | Variation of dropdown. Tiny is used for small numbers / tiny option ranges. Compact works well with adjacent buttons, like with compact pagination. | "compact" | "default" | "tiny" | "default" |
Events #
Event | Description | Type |
---|---|---|
duetBlur | Emitted when the select loses focus. | CustomEvent<{ originalEvent?: Event; component: "duet-select"; value: string; }> |
duetChange | Callback for when the value changed. | CustomEvent<{ originalEvent?: Event; component: "duet-select"; value: string; }> |
duetFocus | Emitted when the select has focus. | CustomEvent<{ originalEvent?: Event; component: "duet-select"; value: string; }> |
Methods #
setFocus(options?: FocusOptions) => Promise<void>
#
Sets focus on the specified duet-select
. Use this method instead of the global
select.focus()
.
Parameters #
Name | Type | Description |
---|---|---|
options | FocusOptions |
Returns #
Type: Promise<void>
Slots #
Slot | Description |
---|---|
"tooltip" | Use to place a tooltip alongside the label. |
Usage #
This section includes guidelines for designers and developers about the usage of this component in different contexts.
When to use #
- To let user choose one option from an options menu.
- When you have more than 6 options to choose from.
- When you don’t know how many options there will be.
When not to use #
Accessibility #
This component has been validated to meet the WCAG 2.1 AA accessibility guidelines. You can find additional information regarding accessibility of this component below.
- Select components uses a basic HTML
<select>
element behind the scenes and offers similar functionality and API for its users. label
property is always required for an accessible textarea control.labelHidden
property hides the above label visually, but still keeps it accessible for assistive technologies.- Use
role
property to define a specific role attribute for the select. - When you need to disable the select, use
disabled
property as it conveys this information correctly to assistive technologies as well. accessibleActiveDescendant
property can be used to indicate the id of a related component’s visually focused element.accessibleControls
property can be used to add an aria-controls attribute. Use the attribute to indicate the id of a component controlled by this component.accessibleOwns
property can be used to indicate the id of a component owned by the select.accessibleDescribedBy
property can be used to indicate the id of a component which contains descriptive/help text related to the select.
Integration
For integration, event and theming guidelines, please see Using Components. This documentation explains how to implement and use Duet’s components across different technologies like Angular, React or Vanilla JavaScript.
Tutorials
Follow these practical tutorials to learn how to build simple page layouts using Duet’s CSS Framework, Web Components and other features:
Building Layouts
TutorialsUsing CLI Tools
TutorialsCreating Custom Patterns
TutorialsServer Side Rendering
TutorialsSharing Prototypes
TutorialsUsage With Markdown
Troubleshooting
If you experience any issues while using a component, please head over to the Support page for more guidelines and help.