Responsive Tabs with one consistent API
adaptive component design.
one stable public API (items, value, onChange), internal swap of presentation by breakpoint, and shared selection state.
exposing two different APIs or duplicating state logic per mode.
What's really being asked
The interviewer checks whether you can hide implementation variance behind a stable interface, a core design-system skill. The trap is leaking the responsive complexity to consumers.
The full answer
Define one public API: a list of tab items, a selected value, and an onChange callback, modeled as a controlled component with a single source of truth for selection. Internally, detect the environment with a breakpoint or media query (or a capability like touch) and render the appropriate presentation: a horizontal tab bar with keyboard arrow navigation on desktop, and a swipeable, paged view with snap on mobile. Both presentations read and write the same selection state, so switching viewport sizes keeps the active tab correct. Factor shared concerns, accessibility roles like tablist/tab/tabpanel, focus management, and the selection reducer, into a common hook reused by both renderers. Consumers write the same JSX everywhere.
The mistakes people make
Shipping two components, TabsDesktop and TabsMobile, with different props, pushing the branching onto consumers. Duplicating selection state per mode so the swipe view and the bar can fall out of sync. Forgetting accessibility, which differs but must be handled in both modes.
What usually comes next
How do you keep ARIA roles correct in both presentations? How do you decide between a breakpoint and a touch-capability check? How do you avoid layout shift when switching modes?
A concrete example
The public Tabs takes items, value, and onChange. A useTabsState hook owns selection and ARIA wiring. Above a breakpoint it renders TabBar (clickable headers, arrow-key navigation); below it renders SwipePager (horizontal snap, swipe updates value). Both call onChange with the same value, so a user who resizes from mobile to desktop keeps the same active tab and the consumer code never changes.
Interview question
How should a Tabs component offer a tab bar on desktop and a swipeable view on mobile without burdening consumers?
- a.Export separate desktop and mobile components with different props
- b.Require consumers to pass a platform flag to choose the renderer
- c.Maintain independent selection state for each presentation mode
- d.Keep one public API and one selection state, swapping the internal presentation by breakpointCorrect
Why? this is the answer
A single stable API over one source of selection state hides the responsive branching internally, so consumers write the same code. Separate components, duplicated state, or a required platform flag all leak complexity outward.
Just read this? Test yourself on what you have been reading.
Read the original → mui.com
- #design-systems
- #responsive
- #component-api
- #tabs
- #accessibility
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on design-systems — each one lists the topics its interview covers.
See open roles