Expandable section

An expandable section is a content section with a text toggle that reveals content that is hidden by default.

Examples

Basic

Uncontrolled

Uncontrolled with dynamic toggle text

Detached

When passing the isDetached property into <ExpandableSection>, you must also manually pass in the same toggleId and contentId properties to both <ExpandableSection> and <ExpandableSectionToggle>. This will link the content to the toggle via ARIA attributes.

Disclosure variation

You can pass in the displaySize="lg" property for a disclosure variation styling.

Indented expandable content

You can indent the expandable content by passing in the isIndented property. This will not affect the expandable toggle.


This content is visible only when the component is expanded.

With custom toggle content

By using the toggleContent prop, you can pass in content other than a simple string such as an icon or a badge. When passing in custom content in this way, you should not pass in any interactive element such as a button.

Truncate expansion

By passing in variant="truncate", the expandable content will be visible up to a maximum number of lines before being truncated, with the toggle revealing or hiding the truncated content. By default the expandable content will truncate after 3 lines, and this can be customized by also passing in the truncateMaxLines prop.

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque nec dignissim turpis, et tristique purus. Phasellus efficitur ante quis dolor viverra imperdiet. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque laoreet, sem ac elementum semper, lectus mauris vestibulum nulla, eget volutpat massa neque vel turpis. Donec finibus enim eu leo accumsan consectetur. Praesent massa diam, tincidunt eu dui ac, ullamcorper elementum est. Phasellus metus felis, venenatis vitae semper nec, porta a metus. Vestibulum justo nisi, imperdiet id eleifend at, varius nec lorem. Fusce porttitor mollis nibh, ut elementum ante commodo tincidunt. Integer tincidunt at ipsum non aliquet.

Props

ExpandableSection

The main expandable section component.
*required
NameTypeDefaultDescription
childrenReact.ReactNodeContent rendered inside the expandable section.
classNamestring''Additional classes added to the expandable section.
contentIdstringId of the content of the expandable section. When passing in the isDetached property, this property's value should match the contenId property of the expandable section toggle sub-component.
displaySize'default' | 'lg''default'Display size variant. Set to "lg" for disclosure styling.
isDetachedbooleanfalseIndicates the expandable section has a detached toggle.
isExpandedbooleanFlag to indicate if the content is expanded.
isIndentedbooleanfalseFlag to indicate if the content is indented.
isWidthLimitedbooleanfalseFlag to indicate the width of the component is limited. Set to "true" for disclosure styling.
onToggle(event: React.MouseEvent, isExpanded: boolean) => void(event, isExpanded): void => undefinedCallback function to toggle the expandable section. Detached expandable sections should use the onToggle property of the expandable section toggle sub-component.
toggleContentReact.ReactNodeReact node that appears in the attached toggle in place of the toggleText property.
toggleIdstringId of the toggle of the expandable section, which provides an accessible name to the expandable section content via the aria-labelledby attribute. When the isDetached property is also passed in, the value of this property must match the toggleId property of the expandable section toggle sub-component.
toggleTextstring''Text that appears in the attached toggle.
toggleTextCollapsedstring''Text that appears in the attached toggle when collapsed (will override toggleText if both are specified; used for uncontrolled expandable with dynamic toggle text).
toggleTextExpandedstring''Text that appears in the attached toggle when expanded (will override toggleText if both are specified; used for uncontrolled expandable with dynamic toggle text).
truncateMaxLinesnumberTruncates the expandable content to the specified number of lines when using the "truncate" variant.
variant'default' | 'truncate''default'Determines the variant of the expandable section. When passing in "truncate" as the variant, the expandable content will be truncated after 3 lines by default.

ExpandableSectionToggle

Acts as the toggle sub-component when the main expandable section component has the isDetached property passed in. Allows for more custom control over the expandable section's toggle.
*required
NameTypeDefaultDescription
childrenReact.ReactNodeContent rendered inside the expandable toggle.
classNamestring''Additional classes added to the expandable toggle.
contentIdstringId of the toggle's respective expandable section content. The value passed into this property should match the contentId property of the main expandable section component.
direction'up' | 'down''down'Direction the toggle arrow should point when the expandable section is expanded.
hasTruncatedContentbooleanfalseFlag to determine toggle styling when the expandable content is truncated.
isExpandedbooleanfalseFlag indicating if the expandable section is expanded.
onToggle(isExpanded: boolean) => voidCallback function to toggle the expandable content.
toggleIdstringId of the toggle. The value passed into this property should match the aria-labelledby property of the main expandable section component.

CSS variables

Expand or collapse columnSelectorVariableValue