Expandable Section
avonni-expandable-section
A titled section that users can expand or collapse to show or hide its content.
Overview
Expandable Section is a Lightning Web Component that wraps content in a titled section that can be collapsed and expanded.
Use it in your own Lightning Web Components to organize long pages into scannable, collapsible regions. You set the title and variant, choose whether it's collapsible and initially open or closed, and place any markup inside its slots.
Use Cases
Form grouping: Break a long form into collapsible sections.
FAQ lists: Show questions that expand to reveal answers.
Detail panels: Hide secondary record details until requested.
Settings groups: Organize related settings under shaded headers.
Custom headers: Use the title slot to add an icon or badge to the header.
Variant Guidelines
base
Lightweight grouping within a card or panel.
shaded
Distinct, visually separated sections on a page.
Use Case Examples
Example 1: Collapsible shaded section
Scenario: Show shipping information in a shaded, collapsible section and react when the user toggles it.
Result: A shaded section with shipping text that collapses and expands; toggling fires toggle with the new closed state.
Example 2: Section with a custom title slot
Scenario: Add an icon next to the header label using the title slot, and start the section collapsed.
Result: A collapsed base section whose header shows an info icon beside bold title text; expanding it reveals the FAQ list.
Specifications
Attributes
closed
If present, close the section.
Boolean
false
closed-icon-alternative-text
Alternative text for the closed icon.
String
—
collapsible
If present, the section is collapsible.
Boolean
false
opened-icon-alternative-text
Alternative text for the open icon.
String
—
title
The title can include text, and is displayed in the header.
String
—
variant
Variant of the section. Valid values include base and shaded.
String
"base"
Methods
focus
Set the focus on the collapse button.
Slots
default
Placeholder for your content in the main section.
title
Placeholder for your content in the title.
Custom Events
toggle
The event fired when the expandable section is closed or opened.
The toggle event returns the following parameters.
closed
boolean
The event properties are as follows.
bubbles
false
This event does not bubble.
cancelable
false
This event has no default behavior that can be canceled. You can't call preventDefault() on this event.
composed
false
This event does not propagate outside of the component in which it was dispatched.
toggle
The event fired when the expandable section is closed or opened.
The toggle event returns the following parameters.
closed
boolean
The event properties are as follows.
bubbles
false
This event does not bubble.
cancelable
false
This event has no default behavior that can be canceled. You can't call preventDefault() on this event.
composed
false
This event does not propagate outside of the component in which it was dispatched.
Styling Hooks
--avonni-expandable-section-base-header-color-background
color
transparent
--avonni-expandable-section-base-header-color-border
color
transparent
--avonni-expandable-section-base-header-color-border-active
color
—
--avonni-expandable-section-base-header-text-color
color
#080707
--avonni-expandable-section-base-header-text-color-focus
color
#080707
--avonni-expandable-section-base-header-text-color-hover
color
#080707
--avonni-expandable-section-base-header-text-decoration-focus
color
none
--avonni-expandable-section-base-header-font-size
font
1rem
--avonni-expandable-section-base-header-font-style
font
normal
--avonni-expandable-section-base-header-font-weight
font
400
--avonni-expandable-section-base-header-spacing-block-start
dimension
0rem
--avonni-expandable-section-base-header-spacing-block-end
dimension
0rem
--avonni-expandable-section-base-header-icon-color-foreground-default
color
—
--avonni-expandable-section-base-header-icon-color-foreground-default-hover
color
—
--avonni-expandable-section-base-header-icon-color-foreground-default-focus
color
—
--avonni-expandable-section-content-spacing-block-start
dimension
—
--avonni-expandable-section-content-spacing-block-end
dimension
—
--avonni-expandable-section-shaded-header-color-background
color
#f3f2f2
--avonni-expandable-section-shaded-header-color-border
color
transparent
--avonni-expandable-section-shaded-header-text-color
color
#080707
--avonni-expandable-section-shaded-header-text-color-focus
color
#080707
--avonni-expandable-section-shaded-header-text-color-hover
color
#080707
--avonni-expandable-section-shaded-header-text-decoration-focus
color
none
--avonni-expandable-section-shaded-header-font-size
font
1rem
--avonni-expandable-section-shaded-header-font-style
font
normal
--avonni-expandable-section-shaded-header-font-weight
font
400
--avonni-expandable-section-shaded-header-spacing-block-start
dimension
0.75rem
--avonni-expandable-section-shaded-header-spacing-block-end
dimension
0.75rem
--avonni-expandable-section-shaded-header-icon-color-foreground-default
color
—
--avonni-expandable-section-shaded-header-icon-color-foreground-default-hover
color
—
--avonni-expandable-section-shaded-header-icon-color-foreground-default-focus
color
—
Key Considerations
Collapsible required for toggling: Without
collapsible, the section stays open and the toggle control is hidden.Initial state: Use
closedto start collapsed; omit it to start expanded.Slots: Use the
titleslot for rich headers and the default slot for any body markup.Accessibility: Provide both icon alternative-text attributes so the toggle state is announced.
Variant:
shadedadds a background to separate sections;baseis lighter weight.Best Practice: Set
closed-icon-alternative-textandopened-icon-alternative-textso screen readers announce the toggle state, and useshadedto visually separate sections on dense pages.
Troubleshooting Common Issues
Section won't collapse: Confirm the
collapsibleattribute is present.Toggle event not firing: Verify
ontoggleis wired and readevent.detail.closed.Custom header not showing: Ensure the custom markup uses
slot="title".If issues persist: Contact our support team at [email protected] for assistance.
Last updated
Was this helpful?
