Accessibility
The Card component has been designed with accessibility in mind. It can be used with keyboard navigation and includes properties that enhance the experience for users of assistive technologies.
Card accessibility props
| Name | Type | Description |
|---|---|---|
| labelClose | string | Label for the close button that’s announced by screen readers, ensuring users understand the button’s purpose. |
| dataA11ySection | string | Optional identifier for the Card that can be used to improve screen reader navigation and identification of content sections. |
| titleAs | enum | Controls the semantic heading level (h1-h6) of the Card title, helping maintain proper document structure and heading hierarchy. |
CardSection accessibility props
| Name | Type | Description |
|---|---|---|
| titleAs | enum | Controls the semantic heading level of the CardSection title, allowing proper document hierarchy within Cards. |
Keyboard navigation
Card component
Cards themselves are not focusable elements, but they may contain interactive elements like buttons, links, or form controls that are part of the card’s content. These interactive elements follow standard keyboard navigation:
- Interactive elements within cards can be accessed using the
Tabkey - When a Card contains the close button, it can be activated using
EnterorSpace
CardSection component
CardSection components have specific keyboard behaviors when they’re expandable:
- Expandable sections can be toggled with
EnterorSpacewhen focused - Focus is managed automatically when expanding/collapsing sections
- When multiple expandable sections exist in a Card, users can navigate between them using
Tab
Screen reader experience
Card component
Screen readers will announce:
- Card title level as specified by the
titleAsprop (when provided anything other thandiv) - The Card title as specified by the
titleprop (when provided) - The close button with the custom label specified in
labelCloseprop
CardSection component
Screen readers will announce:
- The CardSection title as specified by the
titleprop - The content within the section when expanded
- The expanded/collapsed state for expandable sections
Important restrictions
- CardSection with actions and expandability: When using a clickable or expandable CardSection (
expandable={true}or withonClickhandler), avoid using theactionsprop. If you must use it, ensure it only contains non-interactive elements. This prevents focus management issues and keyboard navigation confusion. Interactive elements in this context can create conflicts with the expanding functionality, leading to poor accessibility and usability.
Example of what to avoid:
<CardSectionexpandabletitle="Flight details"actions={<Button>Edit</Button>} // Avoid interactive elements here>{/* content */}</CardSection>
Recommended approach:
<CardSectionexpandabletitle="Flight details"actions={<Badge type="info">Economy</Badge>} // Non-interactive element is acceptable>{/* content */}</CardSection>
Also, Button component can be passed to the actions prop, but it should be non-interactive (ie. setting asComponent="div" and not defining onClick).
<CardSectionexpandabletitle="Flight details"actions={<Button asComponent="div">Open</Button>} // Non-interactive element is acceptable>{/* content */}</CardSection>
Best practices
Card best practices
- Use semantic heading levels with the
titleAsprop to maintain proper document structure - Provide a descriptive
labelClosethat clearly explains the action (e.g., “Close flight details”) - When creating complex page layouts and using SkipNavigation component on the page, you can use the
dataA11ySectionprop connect the Card with this component
CardSection best practices
- Avoid placing interactive elements in the
actionsprop of expandable CardSection components - Maintain logical heading hierarchy between Card titles and CardSection titles
Examples with accessibility features
Basic Card with accessibility props
<Cardtitle="Flight details"titleAs="h3"dataA11ySection="flight-summary"labelClose="Close flight details"onClose={() => {}}><CardSection><Stack direction="column" spacing="100"><Text>Prague to Barcelona</Text><Text type="secondary">June 21, 2023</Text></Stack></CardSection></Card>
Screen readers will announce heading level 3 of “Flight details”, followed by the title of the card (“Flight details”), with a close button labeled “Close flight details”, followed by the content of the card.
Card with expandable sections
<Card title="Trip itinerary" titleAs="h2" dataA11ySection="trip-details"><CardSection expandable initialExpanded title="Flight information" titleAs="h3"><Text>Prague to Barcelona</Text><Text type="secondary">June 21, 2023</Text></CardSection><CardSection expandable title="Hotel details" titleAs="h3"><Text>Hotel Barcelona</Text><Text type="secondary">Check-in: June 21, 2023</Text></CardSection></Card>
Screen readers will announce a section identified as trip-details with a heading level 2 of “Trip itinerary”, followed by expandable sections with appropriate heading levels. The first section will be initially expanded.