Chip
Chips are interactive controls used for presenting multiple related and dynamic actions.
There are four variations of the Chip - button, filter, radio and input. The button variation behaves like a button and should be used when the offered actions are dynamic, depending on the users context (e.g. actions based on previous choices or suggestions based on given input). The filter variation behaves like a checkbox and is used to enabling and disabling filtering categories. Filter variation can be used also with a popup-menu. The radio variation is similar to the filter but behaves like a radio button. The input variation is used to present items the user has input and which can be removed.
Examples #
<duet-chip checked variation="filter" value="one">first</duet-chip>
<duet-chip variation="filter" value="two">second</duet-chip>
<duet-chip variation="filter" value="dog" icon="category-pet-dog">dog filter</duet-chip>
<duet-chip variation="filter" value="dis" disabled>disabled</duet-chip>
<script>
const filterChips = document.querySelectorAll("duet-chip[variation=filter]")
filterChips.forEach(chip => {
chip.addEventListener("duetChange", () => {
const checked = [...filterChips].filter(chip => chip.checked).map(chip => chip.value).join(", ")
console.log(checked)
})
})
</script> <duet-chip variation="input">first entry</duet-chip>
<duet-chip variation="input" icon="category-pet-dog">second entry</duet-chip> <duet-chip size="large" checked variation="filter" value="one">First</duet-chip>
<duet-chip size="large" variation="filter" value="two">Second</duet-chip>
<duet-chip size="large" variation="filter" value="dog" icon="category-pet-dog">Dog filter</duet-chip>
<duet-chip size="large" variation="filter" icon="category-car" popup="vehicle-popup">Vehicle</duet-chip>
<duet-popup-menu id="vehicle-popup">
<duet-popup-menu-item>Motorbike</duet-popup-menu-item>
<duet-popup-menu-item>Car</duet-popup-menu-item>
<duet-popup-menu-item>Van</duet-popup-menu-item>
<duet-popup-menu-item>Truck</duet-popup-menu-item>
</duet-popup-menu>
<duet-chip size="large" variation="filter" value="cat" icon="category-pet-cat" disabled>Disabled</duet-chip>
<script>
const filterChips = document.querySelectorAll("duet-chip[variation=filter]")
filterChips.forEach(chip => {
chip.addEventListener("duetChange", () => {
const checked = [...filterChips].filter(chip => chip.checked).map(chip => chip.value).join(", ")
console.log(checked)
})
})
</script> Properties #
| Property | Attribute | Description | Type | Default |
|---|---|---|---|---|
accessibleDescribedBy | accessible-described-by | Indicates the id or a string of space seperated ids of a component(s) that describes the input. | string | "" |
accessibleExpanded | accessible-expanded | If the component expands or collapses adjacent content, then use this property to add the aria-expanded attribute to the opening element. Set the value to convey the current expanded (true) or collapsed (false) state of the content. | boolean | undefined |
accessibleLabel | accessible-label | Adds accessible label for the chip that is used by screen readers and other assistive technology. Has effect only with "button" variation as for the other variations the accessible label is automatically generated. | string | undefined |
accessiblePopup | accessible-popup | Use this property to add an aria-haspopup attribute. | string | "false" |
checked | checked | Checked state of the filter chip. | boolean | false |
disabled | disabled | Makes the chip look inactive and announced as unavailable to assistive technologies. Prevents the default action. Not available for the input variation. | boolean | false |
icon | icon | Icon to display to the left of the chip content. | string | "" |
identifier | identifier | Adds a unique identifier for the chip. | string | undefined |
name | name | Name attribute of the html input (filter) or button. | string | undefined |
popup | popup | Id of the DuetPopupMenu that is controlled by the chip. Works only with "filter" variation. | string | undefined |
size | size | Size of the chip. Use "large" for a chip that has the same height as default duet-input and duet-button. | "large" | "medium" | "medium" |
theme | theme | Theme of the button. | "" | "default" | "turva" | "" |
value | value | The value of the html input when used as filter, or the button's value. | string | undefined |
variation | variation | Variation of the chip. Button should be used to present a list of actions or suggestions. It behaves like a button and must be used together with a click handler. Filter acts like a checkbox, it can be toggled on or off, and it should be used with a value. Filter can also be used with a popup-menu - then the initial text describes the type of category of filtering, and the selection from the popup-menu sets the filter value. Input represents items input by the user, and the chip can be removed with a click. Radio behaves like a radio button, it can be toggled on or off in a group, and it should be used with a value and name. | "button" | "filter" | "input" | "radio" | "button" |
Events #
| Event | Description | Type |
|---|---|---|
duetBlur | Emitted when the chip loses focus. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-chip"; }> |
duetChange | Emitted when the checked property has changed (applicable only for the filter variation). | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-chip"; }> |
duetFocus | Emitted when the chip receives focus. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-chip"; }> |
duetRemove | Emitted when an input chip is removed. | CustomEvent<{ originalEvent?: Event; checked: boolean; value: string; component: "duet-chip"; }> |
Methods #
removeChip() => Promise<void> #
Removes input chip. Use this method instead of the native remove() so the component can
emit appropriate event
Returns #
Type: Promise<void>
setFocus(options?: FocusOptions) => Promise<void> #
Sets focus. Use this method instead of the global focus().
Parameters #
| Name | Type | Description |
|---|---|---|
options | FocusOptions |
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 #
- When the actions or items are dynamic
- When there are multiple related actions
When not to use #
- When the actions or items are static, i.e. the same for all users. Use e.g. a button component or a toggle component instead
- When the actions are not related to each other
- When there are only one or two actions
Variations #
This section describes the different component variations, their purpose, and when to use each variation.
| Name | Purpose |
|---|---|
button | Actionable controls - provide the action either with a onclick event listener or the Chips url attribute. |
filter | Toggle items on and off. |
radio | Select one item from a group of items. |
input | Collect items input by the user, typically from a predefined set, e.g. emails from an address book or illnesses from a disease list. |
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.
- Use
accessibleLabelproperty to add accessible label for the Chip if the text content of the Chip would not be informative enough for users of assistive technologies (only for "button" variation) - The accessible label for other variations than "button" is set automatically. For "radio" it is just the text content (because the contained input element must be taken out of shadow DOM). For "input" it communicates if the chip is selected for deletion. For "filter" with a popup-menu when a selction has been made the accessible label combines the Chip's text content with that of the selected item.
Additional considerations #
- The text label in a Chip should be short, no more than 20 characters
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.