Collapse

Accessibility

Accessibility Props

NameTypeDescription
expandButtonLabelstringSpecifies the accessible label of the button when the content is collapsed. This should clearly indicate the action to expand the content.
collapseButtonLabelstringSpecifies the accessible label of the button when the content is expanded. This should clearly indicate the action to collapse the content.
labelstringDefines the visible heading that also serves as the accessible name for the collapsible section.
customLabelReact.NodeAllows replacing the default heading with custom content while maintaining the click target for keyboard accessibility.

Automatic Accessibility Features

  • The component automatically manages ARIA attributes:
    • aria-expanded is automatically set to true or false based on the current state.
    • aria-controls is automatically set to reference the collapsible content.

Best Practices

  • Always provide descriptive expandButtonLabel and collapseButtonLabel that clearly indicate the action.
  • Use clear and concise labels that describe the content being collapsed.
  • When using customLabel, ensure it includes text that can be announced by screen readers.
  • If the collapsed content includes interactive elements, make sure they’re not focusable when collapsed.
  • All label texts should always be translated to the user’s language.
  • When using the actions prop, ensure all action buttons have descriptive labels and are keyboard accessible to maintain a logical tab order in the component.

Focus Management

  • When expanded, focus moves from the label to the button to the content inside.
  • When collapsed, focus will skip over any focusable elements inside the collapsed content.

Keyboard Navigation

  • Tab: Moves focus to the collapse label or expand/collapse button.
  • Enter or Space: When focus is on the label or button, toggles the collapsed state.
  • Focus order: Focus moves from the label to the button to the content inside (when expanded).
  • When collapsed, focus will skip over any focusable elements inside the collapsed content.

Examples

Basic Usage with Required Accessibility Labels

import { Collapse, Text } from "@kiwicom/orbit-components";
<Collapse
label="Flight Information"
expandButtonLabel="Show flight details"
collapseButtonLabel="Hide flight details"
>
<Text>Flight number: KL1234</Text>
<Text>Departure: 10:00</Text>
<Text>Arrival: 12:30</Text>
</Collapse>;

Expanded State

import { Collapse, Text } from "@kiwicom/orbit-components";
<Collapse
label="Passenger Details"
expandButtonLabel="Show passenger details"
collapseButtonLabel="Hide passenger details"
expanded={true}
>
<Text>Name: John Smith</Text>
<Text>Passport: AB123456</Text>
</Collapse>;

With Actions

import { Collapse, Button, Text } from "@kiwicom/orbit-components";
<Collapse
label="Filter Options"
expandButtonLabel="Show filters"
collapseButtonLabel="Hide filters"
actions={
<Button type="white" size="small">
Reset
</Button>
}
>
<Text>Filter controls...</Text>
</Collapse>;

With Custom Label

import { Collapse, Badge, Text } from "@kiwicom/orbit-components";
<Collapse
customLabel={<Badge type="info">2 baggages</Badge>}
expandButtonLabel="Show baggage details"
collapseButtonLabel="Hide baggage details"
>
<Text>Cabin baggage: 1 × 8kg</Text>
<Text>Checked baggage: 1 × 23kg</Text>
</Collapse>;