From 8ff920617d37ceec011db3e310c27c390239f155 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Fri, 17 Oct 2025 14:42:19 -0400 Subject: [PATCH] feat(ExpandableSection): added aria labeling --- .../ExpandableSection/ExpandableSection.tsx | 10 ++++++++++ .../ExpandableSectionToggle.tsx | 8 ++++++++ .../__tests__/ExpandableSection.test.tsx | 17 +++++++++++++++++ .../__tests__/ExpandableSectionToggle.test.tsx | 17 +++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx b/packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx index 82c09ca1d39..1f39a289f8d 100644 --- a/packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx +++ b/packages/react-core/src/components/ExpandableSection/ExpandableSection.tsx @@ -56,6 +56,10 @@ export interface ExpandableSectionProps extends Omit undefined, isDetached: false, @@ -196,6 +202,8 @@ class ExpandableSection extends Component ) })} + aria-label={toggleAriaLabel} + aria-labelledby={toggleAriaLabelledBy} > {toggleContent || computedToggleText} diff --git a/packages/react-core/src/components/ExpandableSection/ExpandableSectionToggle.tsx b/packages/react-core/src/components/ExpandableSection/ExpandableSectionToggle.tsx index d42aa79b8d1..e44ba385eda 100644 --- a/packages/react-core/src/components/ExpandableSection/ExpandableSectionToggle.tsx +++ b/packages/react-core/src/components/ExpandableSection/ExpandableSectionToggle.tsx @@ -30,6 +30,10 @@ export interface ExpandableSectionToggleProps extends Omit void; /** Flag indicating that the expandable section and expandable toggle are detached from one another. */ isDetached?: boolean; + /** Accessible name via human readable string for the expandable section toggle. */ + toggleAriaLabel?: string; + /** Accessible name via space delimtted list of IDs for the expandable section toggle. */ + toggleAriaLabelledBy?: string; } export const ExpandableSectionToggle: React.FunctionComponent = ({ @@ -42,6 +46,8 @@ export const ExpandableSectionToggle: React.FunctionComponent (
) })} + aria-label={toggleAriaLabel} + aria-labelledby={toggleAriaLabelledBy} > {children} diff --git a/packages/react-core/src/components/ExpandableSection/__tests__/ExpandableSection.test.tsx b/packages/react-core/src/components/ExpandableSection/__tests__/ExpandableSection.test.tsx index b4e77de49d9..22b067f29e5 100644 --- a/packages/react-core/src/components/ExpandableSection/__tests__/ExpandableSection.test.tsx +++ b/packages/react-core/src/components/ExpandableSection/__tests__/ExpandableSection.test.tsx @@ -191,3 +191,20 @@ test('Renders with class pf-m-detached when isDetached is true and direction is expect(screen.getByText('Test content').parentElement).toHaveClass('pf-m-detached'); }); + +test('Renders with aria-label when toggleAriaLabel is passed', () => { + render(); + + expect(screen.getByRole('button')).toHaveAccessibleName('Test label'); +}); + +test('Renders with aria-labelledby when toggleAriaLabelledBy is passed', () => { + render( + <> +
Test label
+ + + ); + + expect(screen.getByRole('button')).toHaveAccessibleName('Test label'); +}); diff --git a/packages/react-core/src/components/ExpandableSection/__tests__/ExpandableSectionToggle.test.tsx b/packages/react-core/src/components/ExpandableSection/__tests__/ExpandableSectionToggle.test.tsx index 8a088eef393..332b3149050 100644 --- a/packages/react-core/src/components/ExpandableSection/__tests__/ExpandableSectionToggle.test.tsx +++ b/packages/react-core/src/components/ExpandableSection/__tests__/ExpandableSectionToggle.test.tsx @@ -30,3 +30,20 @@ test('Renders with class pf-m-detached when isDetached is true', () => { expect(screen.getByTestId('test-id')).toHaveClass('pf-m-detached'); }); + +test('Renders with aria-label when toggleAriaLabel is passed', () => { + render(); + + expect(screen.getByRole('button')).toHaveAccessibleName('Test label'); +}); + +test('Renders with aria-labelledby when toggleAriaLabelledBy is passed', () => { + render( + <> +
Test label
+ + + ); + + expect(screen.getByRole('button')).toHaveAccessibleName('Test label'); +});