Collapsible New
Collapsible is a disclosure component used to reveal additional content. It should contain a heading, followed by any additional content that is revealed on click.
Examples
<duet-collapsible heading="Click to open details">
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
Aperiam impedit, possimus minima repudiandae.
</duet-collapsible>
<script>
// Select the above component
var collapsible = document.querySelector("duet-collapsible")
// Listen for toggle events
collapsible.addEventListener("duetToggle", function(e) {
console.log("open", e.target.open)
})
</script>
<duet-collapsible heading="Click to open details">
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
Aperiam impedit, possimus minima repudiandae.
</duet-collapsible>
<duet-divider margin="small"></duet-divider>
<duet-collapsible heading="Click to open">
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
</duet-collapsible>
<duet-divider margin="small"></duet-divider>
<duet-collapsible heading="Click to">
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
</duet-collapsible>
<duet-divider margin="small"></duet-divider>
<duet-collapsible heading="Click to open">
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
</duet-collapsible>
<duet-collapsible heading="Click to open details" open>
Lorem ipsum dolor sit, amet consectetur adipisicing elit.
</duet-collapsible>
Properties #
Property | Attribute | Description | Type | Default |
---|---|---|---|---|
heading | heading | The content for the collapsible heading. | string | "" |
margin | margin | Controls the margin of the component. | "auto" | "none" | "auto" |
open | open | Is the component expanded or collapsed. | boolean | false |
theme | theme | Theme of the definition list. | "" | "default" | "turva" | "" |
Events #
Event | Description | Type |
---|---|---|
duetToggle | Event emitted when opened/closed | CustomEvent<{ component: "duet-collapsible"; originalEvent: MouseEvent | KeyboardEvent; }> |
Methods #
setFocus() => Promise<void>
#
Sets focus on the specified duet-collapsible
. Use this method instead of the global
collapsible.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 hide information with lower priority.
- To put long sentences of information under a section that user can expand or collapse.
- In comparison tables to reveal additional information about insurance coverage.
When not to use #
- For mandatory information or actions.
- For hiding form elements.
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.
heading
property is required for accessibility and works as the label for the collapsible content.- Collapsible toggle has a
role="button"
defined. This makes sure it’s correctly announced by assistive technologies. - Collapsible toggle uses
tabindex="0"
to make it possible to access it using tab key or programmatically move focus to it. - The toggle also uses
aria-expanded
andaria-controls
attributes to convey the expand and collapse functionality to assistive technologies.
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.