Skip to content

Collapse: header (role="button") does not toggle with Space key and has no aria-controls #59684

Closed
react-component/collapse
#457

Description

@droduit

Reproduction link

Edit on CodeSandbox

Steps to reproduce

  1. Render:
<Collapse items={[{ key: '1', label: 'Header', children: <p>Content</p> }]} />
  1. Tab to the panel header and press Space.
  2. Inspect the header element.

What is expected?

  • Space toggles the panel, like Enter, as expected for an element with role="button" (WAI-ARIA Authoring Practices, Button and Accordion patterns), without scrolling the page.
  • The header references its panel with aria-controls, and the panel has the matching id.

What is actually happening?

  • Only Enter toggles the panel; Space scrolls the page instead (WCAG 2.2 SC 2.1.1 Keyboard).
  • The header has role="button" and aria-expanded but no aria-controls, and the panel content has no id (WCAG 2.2 SC 4.1.2).
Environment Info
antd 6.6.8
React 19.x
System Windows 11
Browser Chrome (latest)

The fix belongs to @rc-component/collapse (Panel component, collapsibleProps):

onKeyDown: (e) => {
  if (e.key === 'Enter' || e.key === ' ') {
    e.preventDefault();
    onItemClick?.(panelKey);
  }
},
'aria-controls': panelId,

with a stable panelId (e.g. useId()) set as id on PanelContent. Happy to open the PR on react-component/collapse if that helps.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions