Skip to main content

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

Open in new window
<duet-select label="Kaupunki" placeholder="Valitse…"></duet-select>

<script>
// Save a reference to the above select component
var select = document.querySelector("duet-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>
Open in new window
<duet-select label="Kaupunki" placeholder="Valitse…" expand></duet-select>

<script>
// Save a reference to the above select component
var select = document.querySelector("duet-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" }
]
</script>
Open in new window
<duet-select label="Kaupunki" placeholder="Valitse…" value="2"></duet-select>

<script>
var select = document.querySelector("duet-select");

select.items = [
{ label: "Helsinki", value: "1" },
{ label: "Tampere", value: "2" },
{ label: "Vantaa", value: "3" },
{ label: "Espoo", value: "4" }
];
</script>
Open in new window
<duet-select label="Kaupunki" placeholder="Valitse…" disabled></duet-select>

<script>
var select = document.querySelector("duet-select");

select.items = [
{ label: "Helsinki", value: "1" },
{ label: "Tampere", value: "2" },
{ label: "Vantaa", value: "3" },
{ label: "Espoo", value: "4" }
];
</script>
Open in new window
<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>
Open in new window
<duet-select label="Kaupunki" placeholder="Valitse…"></duet-select>

<script>
var select = document.querySelector("duet-select");

select.items = [
{ label: "Helsinki", value: "1" },
{
label: "Grouped options",
options: [
{ label: "Tampere", value: "2" },
{ label: "Vantaa", value: "3" },
],
},
{ label: "Espoo", value: "4" },
];
</script>
Open in new window
<duet-select label="Kaupunki" placeholder="Valitse…"></duet-select>

<script>
var select = document.querySelector("duet-select");

// you can disable individual options, or entire groups
select.items = [
{ label: "Helsinki", value: "1", disabled: true },
{
label: "Grouped options",
disabled: true,
options: [
{ label: "Tampere", value: "2" },
{ label: "Vantaa", value: "3" },
],
},
{ label: "Espoo", value: "4" },
];
</script>

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
accessibleOwns accessible-owns Indicates the id of a component owned by the select. 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
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 (DuetSelectOptionGroup | DuetSelectOption)[] | string undefined
label label Label for the select. string "label"
labelHidden label-hidden Visually hide the label, but still show it to screen readers. boolean false
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 ""
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

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() => Promise<void> #

Sets focus on the specified duet-select. Use this method instead of the global
select.focus().

Returns #

Type: Promise<void>


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 #

  • When you have less than 6 options to choose from. Consider using either radio, checkbox or choice component instead.

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.


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:

Tutorials

Abstract

Tutorials

Building Layouts

Tutorials

Using CLI Tools

Tutorials

Creating Custom Patterns

Tutorials

Server Side Rendering

Tutorials

Sharing Prototypes

Tutorials

Usage With Markdown

Tutorials

VS Code

Tutorials

Zeplin


Troubleshooting

If you experience any issues while using a component, please head over to the Support page for more guidelines and help.