Skip to the page

Overlays and disclosure widgets · mid

Tabs and accordion with keyboard support

Tabs use tablist, tab and tabpanel roles with one tab in the Tab order and arrow keys to move between tabs; an accordion uses a heading with a button that toggles aria-expanded; both are built as compound components with controlled and uncontrolled modes and can lazy-load panel content.

The notes

What you must know

  • Tabs roles (APG): role='tablist' (labelled) → role='tab' with aria-selected and aria-controls → role='tabpanel' with aria-labelledby; a panel with no focusable content gets tabIndex={0}.
  • Roving tabindex: the active tab has tabIndex 0, others −1; Left/Right move and wrap (Up/Down for vertical with aria-orientation='vertical'); Home/End go to the ends; Tab moves into the panel.
  • Activation: automatic (select on focus) only when panels show instantly; manual (Enter/Space) when panels load data.
  • Lazy panels (Atlassian asked this): render a panel the first time it is opened, then keep it mounted (hidden) or unmount — say the trade-off (state kept vs memory); show a loader and cache fetched data.
  • Compound API: <Tabs value onChange defaultValue><TabList><Tab value='a'/></TabList><TabPanel value='a'/></Tabs> with context; ids from useId; children matched by value, not by index.
  • Accordion (APG): each header is a button inside a heading (aria-level), aria-expanded and aria-controls; Enter/Space toggle; single-open or multi-open mode; regions only when there are few panels.
  • Native option: <details>/<summary> gives an accessible disclosure with no JavaScript; details elements sharing a name attribute behave as an exclusive accordion in current browsers.

The red pen

Common traps: mistake → fix

  • Mistake: Divs with onClick as tabs

    Fix: no keyboard support and no semantics.

  • Mistake: Every tab in the Tab order

    Fix: keyboard users must Tab through all tabs; use roving tabindex.

  • Mistake: Match panels to tabs by array index

    Fix: reordering children breaks it.

  • Mistake: Automatic activation on panels that fetch

    Fix: arrowing through tabs fires many requests.

Easy to hard

Questions interviewers ask, easy to hard

  1. Build MUI-style tabs, controlled and uncontrolled.
  2. Add keyboard support according to the ARIA pattern.
  3. Load each panel's data only when first opened.
  4. Build an accordion where only one section is open.

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview