Card: address accessibility review feedback#7852
Conversation
🦋 Changeset detectedLatest commit: c491a2d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
…react into liuliu/card-improvements
There was a problem hiding this comment.
Pull request overview
Updates the experimental Card component to address external accessibility review feedback by tightening runtime/dev-time validation, improving a11y-focused examples and docs, and aligning with the repo’s data-component instrumentation approach.
Changes:
- Added
data-componentattributes acrossCardand subcomponents; added anasprop to support rendering as a labelled<section>landmark (with runtime dev warnings for missing accessible name). - Made
childrenrequired and added a dev warning +nullrender for empty cards, with new unit test coverage. - Improved Storybook examples and docs (new feature stories, removed inline styles in stories, expanded docs.json props coverage).
Show a summary per file
| File | Description |
|---|---|
| packages/react/src/Card/Card.tsx | Adds children requirement, as="section" support + a11y warnings, and data-component attributes for Card + subcomponents. |
| packages/react/src/Card/Card.test.tsx | Adds tests for data-component, empty-children behavior, and as="section" landmark behavior/warnings. |
| packages/react/src/Card/Card.stories.tsx | Updates default/playground stories; uses CSS module decorator instead of inline max-width styles; updates metadata example content. |
| packages/react/src/Card/Card.stories.module.css | Introduces shared Storybook layout classes (width constraint, list layout, custom content layout). |
| packages/react/src/Card/Card.features.stories.tsx | Adds feature stories demonstrating menu usage, landmark section usage, list usage, and interactive content a11y labeling patterns. |
| packages/react/src/Card/Card.docs.json | Documents children requirement, as prop guidance, and props for Card.Description, Card.Menu, and Card.Metadata; adds new stories to docs. |
| .changeset/lucky-terms-sing.md | Declares a minor release for the new props/requirements and instrumentation updates. |
Copilot's findings
- Files reviewed: 7/16 changed files
- Comments generated: 2
|
👋 Hi from github/github-ui! Your integration PR is ready: https://github.com/github/github-ui/pull/21133 |
Addresses accessibility-review feedback from Tetralogical (github/accessibility#10648) for the experimental
Cardcomponent. Part of https://github.com/github/primer/issues/6672Changelog
Default example - metadata content
Default story no longer uses "Updated 2 hours ago" (which would have pulled in
RelativeTime's outstanding accessibility issues). Replaced with<PeopleIcon /> 3 contributors. The metadata slot is also now documented inCard.docs.jsonand JSDoc to confirm it accepts any content, including other components.Data-component attributes
Added
data-componentattributes per ADR-023 toCard,Card.Icon,Card.Image,Card.Heading,Card.Description,Card.Metadata, andCard.Menu.Grouping content for accessibility — new
aspropCards can now opt into being a
<section>landmark via a newasprop. The prop is typed soas="section"requiresaria-labeloraria-labelledby.Interactive content
New
WithMenufeature story showing an action menu inside a Card with an accessible name on the trigger (aria-label="More options for primer/react").Custom content variant
CustomContentstory now uses an<h3>heading instead of<strong>, resolving the WCAG 2.2 SC 1.3.1 violation.Props section
Card.docs.jsonand JSDoc now documentCard.Description,Card.Menu, andCard.Metadata.Empty props
childrenis now required onCard. Empty cards log a dev warning and returnnull. Tests cover both paths.Inline style attributes on wrapping divs
Added
Card.stories.module.csswith aWidthConstraintContainerclass instead ofstyle={{…}}props in the stories.Rollout strategy
Testing & Reviewing
Merge checklist