Home
← All questions

Tabs component | Frontend Machine Coding

EasyPremiumMachine Coding

Frontend Machine Coding interview practice: Build an accessible tabs component that shows one panel at a time.

Problem

Build a reusable Tabs component.

Requirements

  • Render a list of tab headers and show the active tab's panel only.
  • Clicking a header activates that tab.
  • (Bonus) Keyboard navigation (arrow keys) and ARIA roles (tablist, tab, tabpanel, aria-selected).
  • (Bonus) Lazy-mount panel content; controlled vs uncontrolled active tab.

Hints / Approach

  • Keep activeIndex in state; render tabs[activeIndex].content.
  • Data-driven API: <Tabs items={[{ label, content }]} />.
  • For accessibility, link each tab to its panel with aria-controls / id and manage focus with tabIndex.
Premium question

Unlock the in-browser editor, test cases, and model solution with Mentoxis Premium.

Unlock with Premium