CollapsibleCard: Add HeaderDescription subcomponent#76867
CollapsibleCard: Add HeaderDescription subcomponent#76867
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Warning: Type of PR label mismatch To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.
Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task. |
Add a `CollapsibleCard.HeaderDescription` subcomponent that provides an `aria-describedby` relationship between supplementary header content (e.g. status badges, summaries) and the collapsible trigger button. The component uses React context to communicate its auto-generated ID to the parent `Header`, which sets `aria-describedby` on the trigger. Content is rendered with `aria-hidden="true"` so assistive technologies consume it only through the description relationship, avoiding double announcements. Also refactors the DataForm card layout to use `HeaderDescription` instead of the previous manual `aria-describedby` + `useId()` approach. Made-with: Cursor
1305870 to
fe262e6
Compare
|
Size Change: +443 B (+0.01%) Total Size: 7.73 MB
ℹ️ View Unchanged
|
|
Flaky tests detected in 1abf7e0. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/23660708617
|
What?
Add a
CollapsibleCard.HeaderDescriptionsubcomponent to@wordpress/uifor supplementary header content (badges, summaries) with properaria-describedbysemantics. Refactor the DataForm card layout to use it.Follow-up to #76282, based on the discussion between @ciampo and @mirka. Part of #76100.
Why?
The manual
useId()+aria-hidden+aria-describedbypattern used in #76282 is generic enough to belong inCollapsibleCarditself, so consumers don't have to wire it up every time.How?
HeaderDescriptionrenders its children witharia-hidden="true"and an auto-generated ID. A React context communicates the ID to the parentHeader, which setsaria-describedbyon the trigger. When noHeaderDescriptionis present,aria-describedbyis omitted.The component does not apply any layout styles by default — consumers can pass a
classNameto control how the description participates in the header layout (e.g. the DataForm card layout usesdisplay: contents).Implementation details
New files (
@wordpress/ui)collapsible-card/header-description.tsx— the subcomponent (aria-hidden,useId, no default layout styles)collapsible-card/context.ts—HeaderDescriptionIdContextfor ID registrationModified files
collapsible-card/header.tsx— provides context, conditionally setsaria-describedbycollapsible-card/types.ts— addedHeaderDescriptionPropscollapsible-card/index.ts— exportsHeaderDescriptioncollapsible-card/test/index.test.tsx— 5 new testscollapsible-card/stories/index.story.tsx—WithHeaderDescriptionstoryDataForm card layout refactoring (
@wordpress/dataviews)useId()+aria-hiddendiv +aria-describedbywith<CollapsibleCard.HeaderDescription>display: contentsstyle remains in the DataForm's own SCSS, passed viaclassNameTesting Instructions
CollapsibleCardunit tests passWithHeaderDescriptionstory and verifyaria-describedbyin dev toolsDataForm / LayoutCardcollapsible cards still workAI Tooling
Cursor + Claude Opus 4.6