import { useState, MouseEvent } from 'react'; import { ExpandableSection, ExpandableSectionToggle, Stack, StackItem } from '@patternfly/react-core'; import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon'; export const ExpandableSectionWithHeading = () => { const [isExpanded1, setIsExpanded1] = useState(false); const [isExpanded2, setIsExpanded2] = useState(false); const [isExpandedDetached, setIsExpandedDetached] = useState(false); const onToggle1 = (_event: MouseEvent, isExpanded: boolean) => { setIsExpanded1(isExpanded); }; const onToggle2 = (_event: MouseEvent, isExpanded: boolean) => { setIsExpanded2(isExpanded); }; const onToggleDetached = (isExpanded: boolean) => { setIsExpandedDetached(isExpanded); }; return (

Document with Expandable Sections

This demonstrates how to use expandable sections with proper heading semantics.

{/* Using toggleWrapper prop for proper heading semantics */}

This content is visible only when the component is expanded. The toggle text above functions as a proper heading in the document structure, which is important for screen readers and other assistive technologies.

When using the toggleWrapper prop with heading elements (h1-h6), the button is rendered inside the heading element, maintaining proper semantic structure.

Detached Variant with Heading

You can also use the detached variant with heading semantics:

Detached Toggle with Heading

This is detached content that can be positioned anywhere in the DOM.

Custom Content with Heading

You can also use custom content within heading wrappers:

Custom Heading Content with Icon } onToggle={onToggle2} isExpanded={isExpanded2} >

This expandable section uses custom content with an icon inside a heading wrapper.

); };