An accordion is made up of one or more collapsible sections with content. Each accordion item is made up of a header and a trigger button, and the panel that contains the collapsible content.
Lustre.Ui.Accordion.view []
[ Lustre.Ui.Accordion.item
"..."
[]
(Lustre.Ui.Accordion.heading []
[ Lustre.Ui.Accordion.trigger []
[ Html.span [] [ Html.text "..." ] ]
]
)
(Lustre.Ui.Accordion.panel []
[ Html.p [] [ Html.text "..." ]
, Lustre.Ui.Accordion.close []
[ Html.text "..." ]
]
)
]accordion.view is the container for all accordion items. It
manages keyboard interaction and open state for each item.
Each accordion.item represents a single collapsible section
within the accordion. It must have a unique name within the accordion to
identify it.
An accordion.heading contains the trigger button for the
item as its only child.
The accordion.trigger is the button that toggles the open
state of an accordion item. It must not contain any other interactive
elements.
The accordion.panel contains the collapsible content for the
item.
The optional accordion.close trigger can be placed within the
panel content to provide an additional way to close the accordion item.
The accordion component follows the WAI-ARIA Authoring Practices for the accordion pattern. This means appropriate roles, ARIA attributes, and keyboard interactions are handled for you, including:
role "region" on the accordion root, with managed aria-orientation
for horizontal or vertical accordions.
role "heading" on each accordion item heading, with a default aria-level
of 3.
role "button" on each accordion item trigger, with managed aria-expanded,
and aria-controls attributes.
role "region" on each accordion item panel, with managed aria-labelledby
attribute.
Keyboard interactions for navigation between accordion item triggers using Arrow Up/Down, Arrow Left/Right, Home, and End keys.
Retention of focus when accordion items are closed.
Avoid accordions with only one item, as they do not provide any functionality
not already provided by the native <details> HTML element.
You can use these recipes as starting points to build common types of accordions. Copy and paste them into your apps and adapt them as needed!
The basic scaffold for any accordion. In this default configuration, the state of the accordion is uncontrolled and managed internally. Only one item can open at a time and keyboard navigation does not loop when reaching the first or last item.
Lustre.Ui.Accordion.view []
[ Lustre.Ui.Accordion.item "..."
[]
(Lustre.Ui.Accordion.heading []
[ Lustre.Ui.Accordion.trigger [] [ Html.span [] [ Html.text "..." ] ] ]
)
(Lustre.Ui.Accordion.panel []
[ Html.p [] [ Html.text "..." ]
, Lustre.Ui.Accordion.close [] [ Html.text "..." ]
]
)
, Lustre.Ui.Accordion.item "..."
[]
(Lustre.Ui.Accordion.heading []
[ Lustre.Ui.Accordion.trigger [] [ Html.span [] [ Html.text "..." ] ] ]
)
(Lustre.Ui.Accordion.panel []
[ Html.p [] [ Html.text "..." ]
, Lustre.Ui.Accordion.close [] [ Html.text "..." ]
]
)
]This configuration allows multiple accordion items to be open at once, and keyboard navigation will loop back to the first item after the last, and vice versa.
Lustre.Ui.Accordion.view
[ Lustre.Ui.Accordion.multiple, Lustre.Ui.Accordion.loop True ]
[ Lustre.Ui.Accordion.item "..."
[]
(Lustre.Ui.Accordion.heading []
[ Lustre.Ui.Accordion.trigger [] [ Html.span [] [ Html.text "..." ] ] ]
)
(Lustre.Ui.Accordion.panel []
[ Html.p [] [ Html.text "..." ]
, Lustre.Ui.Accordion.close [] [ Html.text "..." ]
]
)
, Lustre.Ui.Accordion.item "..."
[]
(Lustre.Ui.Accordion.heading []
[ Lustre.Ui.Accordion.trigger [] [ Html.span [] [ Html.text "..." ] ] ]
)
(Lustre.Ui.Accordion.panel []
[ Html.p [] [ Html.text "..." ]
, Lustre.Ui.Accordion.close [] [ Html.text "..." ]
]
)
]By explicitly setting the open attribute on an accordion item, it becomes
controlled and will always be open unless the the open attribute is changed.
This lets you pin certain items open or closed regardless of user interaction.
Lustre.Ui.Accordion.view
[ Lustre.Ui.Accordion.open True ]
[ Lustre.Ui.Accordion.item "..."
[ Lustre.Ui.Accordion.open True ]
(Lustre.Ui.Accordion.heading []
[ Lustre.Ui.Accordion.trigger [] [ Html.text "..." ] ]
)
(Lustre.Ui.Accordion.panel [] [ todo ])
, Lustre.Ui.Accordion.item "..."
[]
(Lustre.Ui.Accordion.heading []
[ Lustre.Ui.Accordion.trigger [] [ Html.text "..." ] ]
)
(Lustre.Ui.Accordion.panel [] [ Html.text "..." ])
]The root accordion element is a container for multiple accordion items.
<lustre-accordion>default_value, horizontal, label,
loop, multiple, single, value,
vertical.
This element has a default display of block.
The accordion supports keyboard navigation between accordion item triggers using the following keys in addition to the standard tabbing behaviour:
Authors may provide an accessible label for the accordion to
help assistive technologies identify it, but this is not required.
The following attributes must not be set manually on the accordion, as these are managed by the component and are necessary for accessibility:
roleEach accordion item represents a single collapsible section within the accordion. It must have a unique name within the accordion to identify it.
<lustre-accordion-item>on_hide, on_open_change, on_show.
This element has a default display of block.
The following CSS custom states can be used to style this element:
:state(open) is applied when the accordion item is expanded.An accordion heading heading contains the trigger button for an accordion item as its only child.
<lustre-accordion-heading>This element has a default display of block.
The following CSS custom states can be used to style this element:
:state(open) is applied when the containing accordion item is expanded.The following attributes must not be set manually on the heading, as these are managed by the component and are necessary for accessibility:
roleThe accordion trigger is the button that toggles the open state of an accordion item. It must not contain any other interactive elements.
<lustre-accordion-trigger>The following CSS custom states can be used to style this element:
:state(open) is applied when the containing accordion item is expanded.The following attributes must not be set manually on the accordion, as these are managed by the component and are necessary for accessibility:
aria-controlsaria-expandedroleThe accordion panel contains the collapsible content for the containing accordion item.
<lustre-accordion-panel>This element has a default display of block.
The following CSS custom states can be used to style this element:
:state(open) is applied when the containing accordion item is expanded.The following CSS custom properties can be used to style this element or its children:
--accordion-panel-width--accordion-panel-heightWhen the panel is collapsed, any content within is made inert. This prevents focus from moving into the hidden content and ensures screen readers and other assistive technologies do not announce it. Because of this, it's important to make sure that the accordion panel is made visually hidden when collapsed so that sighted users do not try to interact with the panel's content.
The following attributes must not be set manually on the accordion, as these are managed by the component and are necessary for accessibility:
aria-labelledbyThe optional accordion close trigger can be placed within the panel content to provide an additional way to collapse the containing accordion item without navigating back to the item header.
<lustre-accordion-trigger>This element has a default display of inline.
The following CSS custom states can be used to style this element:
:state(open) is applied when the containing accordion item is expanded.The following attributes must not be set manually on the accordion, as these are managed by the component and are necessary for accessibility:
aria-controlsaria-expandedroleProvides an accessible label to an accordion or an item trigger. When used on an accordion, it is announced by assistive technologies to help identify the accordion.
It should be used on an accordion item trigger if the trigger's content does not contain that can be used to automatically generate an accessible label.
In both cases, the label is used for assistive technolgies only and is not visible to sighted users.
Controls whether keyboard navigation in an accordion loops from the last item back to the first and vice versa.
Set the open state of an individual accordion item, making it controlled by your application and overriding any state managed by the containing accordion.
Where possible, it is preferable to manage the open state of accordion items
centrally using the value attribute on the containing accordion,
but this attribute can be useful when you need to pin certain items open or
closed regardless of user interaction.
Note: in a controlled component, the state is managed by your application and must be updated in response to user interaction by handling the
on_open_changeevent.To set whether an accordion item is initially open when first rendered, consider using the
default_openattribute instead.
Set whether an individual accordion item is open by default when
first rendered in an uncontrolled accordion. This value is only taken into
account if the containing accordion does not have its own default_value
attribute.
Set the current open items for a controlled accordion.
Note: in a controlled component, the state is managed by your application and must be updated in response to user interaction by handling the
on_value_changeoron_open_changeevents.To let the component manage its own state, use the
default_valueattribute to set the initial open items instead.
Set the default open items for an uncontrolled accordion. This is a list of item names that should be open when the accordion first renders.
Note: an uncontrolled component is responsible for managing its own state and subsequent changes to the
default_valuewill not be reflected in the component after the initial render.To control the accordion's state from your application, use the
valueattribute instead.
Constrain an accordion to only allow a single item to be open at a time.
Allow multiple accordion items to be open at the same time.
Set an accordion's orientation to horizontal. This changes keyboard navigation to use Arrow Left and Right keys instead of Up and Down.
Set an accordion's orientation to vertical. This is the default behaviour for an accordion and uses Arrow Up and Down keys for keyboard navigation.
Set the heading level for an accordion item's heading. This sets
the aria-level attribute on the heading element to help assistive technologies
understand the structure of the page. The value is clamped between 1 and 9.
An event emitted by an accordion when the open state of any of its items changes. The handler is passed a list of the names of all currently open items.
In a controlled accordion, this event should be used to update your application state with the new open items. Your application may ignore this event to prevent the open state of the accordion from changing.
In an uncontrolled accordion, this event can be used to respond to changes in the accordion's open state, for example by loading content dynamically when an item is opened.
An event emitted by an individual accordion item when its open state changes. The handler is passed the name of the item and its new open state.
Note: like other DOM events, this event bubbles and can be listened for on the containing accordion.
An event emitted by an individual accordion item when it is expanded.
Note: like other DOM events, this event bubbles and can be listened for on the containing accordion.
An event emitted by an individual accordion item when it is collapsed.
Note: like other DOM events, this event bubbles and can be listened for on the containing accordion.