Choice Ready
Choice buttons allow selection of a single or multiple options from a set of predefined options. They are a good alternative to radio buttons, checkboxes, and select menus.
You can set the type of the choice to be either a radio or a checkbox. Using radio type allows you to use Choice component inside Duet’s Choice Group.
Examples
<duet-label>Lemmikit</duet-label>
<duet-caption>Valitse yksi tai useampi vaihtoehto:</duet-caption>
<duet-grid responsive>
<duet-choice label="Kissa" value="kissa" icon="category-pet-cat" checked expand></duet-choice>
<duet-choice label="Koira" value="koira" icon="category-pet-dog" expand></duet-choice>
<duet-choice label="Hevonen" value="hevonen" icon="category-horse" expand></duet-choice>
</duet-grid>
<script>
// Select the above choice group
var choices = document.querySelectorAll("duet-choice")
// Listen for choice changes
choices.forEach(function(element) {
element.addEventListener("duetChange", function(e) {
console.log("Option changed in choice group:", e.detail)
})
})
</script>
<duet-label>Lemmikit</duet-label>
<duet-caption>Valitse yksi tai useampi vaihtoehto:</duet-caption>
<duet-choice label="Kissa" icon="category-pet-cat" checked expand></duet-choice>
<duet-choice label="Koira" icon="category-pet-dog" expand></duet-choice>
<duet-choice label="Hevonen" icon="category-horse" expand></duet-choice>
<duet-label>Lemmikit</duet-label>
<duet-caption>Valitse yksi tai useampi vaihtoehto:</duet-caption>
<duet-choice label="Kissa" icon="category-pet-cat" checked expand collapsible>
<duet-paragraph>LähiTapiola-ryhmä on keskinäiseen yhtiömuotoon perustuva, asiakkaidensa omistama yhtiöryhmä, joka palvelee monia eri asiakasryhmiä. <duet-link url="https://www.lahitapiola.fi/henkilo">LähiTapiolan tuotteet</duet-link> ja palvelut kattavat vahinko-, henki- ja eläkevakuuttamisen sekä sijoittamisen ja säästämisen palvelut. Olemme myös yritysten riskienhallinnan ja henkilöstön työhyvinvoinnin ammattilainen. Omistaja-asiakkaita meillä on lähes 1,6 miljoonaa.</duet-paragraph>
</duet-choice>
<duet-choice label="Koira" icon="category-pet-dog" expand collapsible>
<duet-paragraph>LähiTapiola-ryhmä on keskinäiseen yhtiömuotoon perustuva, asiakkaidensa omistama yhtiöryhmä, joka palvelee monia eri asiakasryhmiä. <duet-link url="https://www.lahitapiola.fi/henkilo">LähiTapiolan tuotteet</duet-link> ja palvelut kattavat vahinko-, henki- ja eläkevakuuttamisen sekä sijoittamisen ja säästämisen palvelut. Olemme myös yritysten riskienhallinnan ja henkilöstön työhyvinvoinnin ammattilainen. Omistaja-asiakkaita meillä on lähes 1,6 miljoonaa.</duet-paragraph>
</duet-choice>
<duet-choice label="Hevonen" icon="category-horse" expand collapsible>
<duet-paragraph>LähiTapiola-ryhmä on keskinäiseen yhtiömuotoon perustuva, asiakkaidensa omistama yhtiöryhmä, joka palvelee monia eri asiakasryhmiä. <duet-link url="https://www.lahitapiola.fi/henkilo">LähiTapiolan tuotteet</duet-link> ja palvelut kattavat vahinko-, henki- ja eläkevakuuttamisen sekä sijoittamisen ja säästämisen palvelut. Olemme myös yritysten riskienhallinnan ja henkilöstön työhyvinvoinnin ammattilainen. Omistaja-asiakkaita meillä on lähes 1,6 miljoonaa.</duet-paragraph>
</duet-choice>
<duet-choice label="Checked state" icon="category-pet-cat" expand disabled checked></duet-choice>
<duet-choice label="Unchecked" icon="category-pet-cat" expand disabled></duet-choice>
<duet-choice label="Kissa" icon="category-pet-cat" value="one" expand disabled>
<div slot="info">Info content</div>
</duet-choice>
<duet-choice-group
value="one"
label="Vakuutus"
direction="horizontal"
name="group"
responsive>
<duet-choice label="Eläinvakuutus" caption="Lorem ipsum dolor sit" type="radio" value="one" expand></duet-choice>
<duet-choice label="Autovakuutus" caption="Lorem ipsum dolor sit" type="radio" value="two" expand></duet-choice>
<duet-choice label="Kotivakuutus" caption="Lorem ipsum dolor sit" type="radio" value="three" expand></duet-choice>
</duet-choice-group>
<duet-choice-group
value="one"
label="Valitse lemmikki"
direction="vertical"
name="group">
<duet-choice type="radio" label="Kissa" icon="category-pet-cat" value="one" expand>
<div slot="info">
LähiTapiola-ryhmä on keskinäiseen yhtiömuotoon perustuva, asiakkaidensa omistama yhtiöryhmä, joka palvelee monia eri asiakasryhmiä. <duet-link url="https://www.lahitapiola.fi/henkilo">LähiTapiolan tuotteet</duet-link> ja palvelut kattavat vahinko-, henki- ja eläkevakuuttamisen sekä sijoittamisen ja säästämisen palvelut. Olemme myös yritysten riskienhallinnan ja henkilöstön työhyvinvoinnin ammattilainen. Omistaja-asiakkaita meillä on lähes 1,6 miljoonaa.
</div>
</duet-choice>
<duet-choice type="radio" label="Koira" icon="category-pet-dog" value="two" expand>
<div slot="info">
LähiTapiola-ryhmä on keskinäiseen yhtiömuotoon perustuva, asiakkaidensa omistama yhtiöryhmä, joka palvelee monia eri asiakasryhmiä. <duet-link url="https://www.lahitapiola.fi/henkilo">LähiTapiolan tuotteet</duet-link> ja palvelut kattavat vahinko-, henki- ja eläkevakuuttamisen sekä sijoittamisen ja säästämisen palvelut. Olemme myös yritysten riskienhallinnan ja henkilöstön työhyvinvoinnin ammattilainen. Omistaja-asiakkaita meillä on lähes 1,6 miljoonaa.
</div>
</duet-choice>
<duet-choice type="radio" label="Hevonen" icon="category-horse" value="three" expand>
<div slot="info">
LähiTapiola-ryhmä on keskinäiseen yhtiömuotoon perustuva, asiakkaidensa omistama yhtiöryhmä, joka palvelee monia eri asiakasryhmiä. <duet-link url="https://www.lahitapiola.fi/henkilo">LähiTapiolan tuotteet</duet-link> ja palvelut kattavat vahinko-, henki- ja eläkevakuuttamisen sekä sijoittamisen ja säästämisen palvelut. Olemme myös yritysten riskienhallinnan ja henkilöstön työhyvinvoinnin ammattilainen. Omistaja-asiakkaita meillä on lähes 1,6 miljoonaa.
</div>
</duet-choice>
</duet-choice-group>
<duet-choice-group
value="one"
label="Valitse vakuutus"
direction="vertical"
name="group">
<duet-choice type="radio" label="Kotivakuutus" value="one" expand>
<div slot="additional">
<duet-paragraph size="small" margin="none">
Testaajankuja 1<br/>
01740 Vantaa<br/>
Vakuutusnumero 1111344221
</duet-paragraph>
</div>
</duet-choice>
<duet-choice type="radio" label="Koira" value="two" expand>
<div slot="additional">
<duet-paragraph size="small" margin="none">
Rusina<br/>
Vakuutusnumero 1111350080
</duet-paragraph>
</div>
</duet-choice>
</duet-choice-group>
<duet-layout>
<div slot="main">
<duet-card padding="large">
<duet-spacer breakpoint="x-small" size="medium"></duet-spacer>
<duet-heading level="h1" visual-level="h3">Lemmikit</duet-heading>
<duet-caption>Valitse yksi tai useampi vaihtoehto:</duet-caption>
<duet-spacer size="medium"></duet-spacer>
<duet-grid alignment="center">
<duet-grid-item margin="none" fill>
<duet-choice label="Kissa" value="kissa" icon="category-pet-cat" checked expand></duet-choice>
</duet-grid-item>
<duet-grid-item margin="none">
<duet-spacer direction="horizontal" size="x-small"></duet-spacer>
<duet-tooltip breakpoint="large" margin="none">
Hello, I’m a tooltip! To close me you can hit ESC key or click the close button.
</duet-tooltip>
</duet-grid-item>
</duet-grid>
<duet-grid alignment="center">
<duet-grid-item margin="none" fill>
<duet-choice label="Koira" value="koira" icon="category-pet-dog" expand></duet-choice>
</duet-grid-item>
<duet-grid-item margin="none">
<duet-spacer direction="horizontal" size="x-small"></duet-spacer>
<duet-tooltip breakpoint="large" margin="none">
Hello, I’m a tooltip! To close me you can hit ESC key or click the close button.
</duet-tooltip>
</duet-grid-item>
</duet-grid>
<duet-grid alignment="center">
<duet-grid-item margin="none" fill>
<duet-choice label="Hevonen" value="hevonen" icon="category-horse" expand></duet-choice>
</duet-grid-item>
<duet-grid-item margin="none">
<duet-spacer direction="horizontal" size="x-small"></duet-spacer>
<duet-tooltip breakpoint="large" margin="none">
Hello, I’m a tooltip! To close me you can hit ESC key or click the close button.
</duet-tooltip>
</duet-grid-item>
</duet-grid>
</duet-card>
</div>
<div slot="sidebar">
<duet-card padding="large" heading="Sivupalsta">
Sivupalstaa voidaan käyttää pääsisältöön liittyvän tiedon näyttämiseen tai
vaihtoehtoisesti nostamaan esiin aiheeseen liittyvää muuta sisältöä.
</duet-card>
</div>
</duet-layout>
Properties #
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
accessibleLabel | accessible-label | Accessible label that is shown for screen reader users in the info toggle. Not visible for normal users. | string | "Lisätietoja tästä valinnasta" |
caption | caption | Additional caption to show inside the label of the choice button. | string | "" |
checked | checked | Checked state of the choice button. | boolean | false |
collapsible | collapsible | Makes the choice button open a new section underneath it when clicked or tapped. This new section can be used to show more options related to this choice. Please note that this feature can’t be used together with the "info" functionality. | boolean | false |
disabled | disabled | Makes the choice component disabled. This prevents users from being able to interact with the choice, and conveys its inactive state to assistive technologies. | boolean | false |
expand | expand | Expands the choice button to fill 100% of the container width. | boolean | false |
groupDirection | group-direction | Determines, whether the control is displayed horizontally or vertically within a group. | "horizontal" | "vertical" | undefined |
groupDisabled | group-disabled | Determines, whether the control is disabled from the parent group. | boolean | undefined |
icon | icon | Icon to display to the left of the choice button label. | string | "" |
identifier | identifier | Adds a unique identifier for the choice button. | string | undefined |
label | label | Label for the choice button. | string | "label" |
margin | margin | Controls the margin of the component. | "auto" | "none" | "auto" |
name | name | Name attribute of the html input that the Choice component controls. | string | undefined |
padding | padding | Controls the padding of the component. | "auto" | "none" | "auto" |
theme | theme | Theme of the choice. | "" | "default" | "turva" | "" |
type | type | Type of the choice button. You can set the type of the choice to be either “radio” or “checkbox”. Depending on this selection we convey the selection type to assistive technologies as well. When type “radio” is chosen it is required to place the choices inside Choice Group component. | "checkbox" | "radio" | "checkbox" |
value | value | The value of the html input that the Choice component controls. | string | undefined |
Events #
Event | Description | Type |
---|---|---|
duetBlur | Emitted when the checkbox loses focus. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-choice"; }> |
duetChange | Emitted when the checked property has changed. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-choice"; }> |
duetFocus | Emitted when the checkbox has focus. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-choice"; }> |
Methods #
setFocus() => Promise<void>
#
Sets focus on the specified duet-choice
. Use this method instead of the global
input.focus()
.
Returns #
Type: Promise<void>
Slots #
Slot | Description |
---|---|
"additional" | Additional content. Anything inserted into this slot is displayed as additional content under the label and caption |
"info" | Info content. Anything inserted into this slot is displayed in a collapsible info box. |
"unnamed default slot" | The component’s primary content. All child nodes that do not have a slot attribute defined are inserted into this primary slot. |
Usage #
This section includes guidelines for designers and developers about the usage of this component in different contexts.
When to use #
When not to use #
- When you have more than 6 options. Prefer using either radio, checkbox or select component instead.
- For “accepting terms of service” and similar functionality. Use checkbox 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.
label
property is always required for accessible choice control.- You can set the type of the choice to be either
radio
orcheckbox
. Depending on this selection we convey the selection type to assistive technologies as well. When typeradio
is chosen it is required to place choices inside Choice Group component. - Use
accessibleLabel
property to create a label for the choice that is only shown for screen readers. Typically, this label text replaces the visible text on the choice for users who use assistive technology. disabled
property makes the choice component disabled. This prevents users from being able to interact with the choice, and conveys its inactive state to assistive technologies.
Additional considerations #
- Consider positioning choices horizontally on larger viewports if surrounding space and label length allows it.
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:
Abstract
TutorialsBuilding Layouts
TutorialsUsing CLI Tools
TutorialsCreating Custom Patterns
TutorialsServer Side Rendering
TutorialsSharing Prototypes
TutorialsUsage With Markdown
TutorialsVS Code
TutorialsZeplin
Troubleshooting
If you experience any issues while using a component, please head over to the Support page for more guidelines and help.