Frontend School

Dynamic Tabbed Content Display

Machine Coding
easy

Dynamic Tabbed Content Display

Easy
Tabs
Dynamic Content
React
Frontend
UI

Overview

On many Amazon retail pages, a vast amount of product information needs to be presented in an organized and user-friendly manner. A common and effective pattern for this is a tabbed interface, which allows users to navigate between different categories of information (e.g., Description, Specifications, Reviews) without overwhelming the initial view. This problem focuses on building a reusable React component that dynamically displays content using tabs.

What you need to do / Task

Your primary task is to implement a Tabs React component that can display dynamic content based on an array of tab items provided as props.

  1. Create the Tabs Component: Implement a functional React component named Tabs.
  2. Accept Props: The Tabs component should accept a prop named items, which is an array of TabItem objects. Each TabItem object will have an id (string), label (string), and content (React.ReactNode).
  3. Render Tab Headers: Dynamically render a list of tab headers (e.g., as buttons) based on the label of each TabItem.
  4. Manage Active Tab: Implement state within the Tabs component to keep track of which tab is currently active. The first tab in the items array should be active by default.
  5. Display Content: Render the content of the currently active tab in a designated content area.
  6. Tab Switching: When a user clicks on a tab header, the component should update its state to make that tab active and display its corresponding content.

UI/UX expectations

  • Clear Tab Headers: Tab headers should be visually distinct and clearly indicate their labels.
  • Active Tab Indication: The currently active tab header should have a clear visual indicator (e.g., different background, bold text, or an underline) to differentiate it from inactive tabs.
  • Dynamic Content Area: The content area below the tab headers should update smoothly to display the content of the selected tab.
  • Basic Accessibility: Consider using appropriate ARIA attributes (e.g., role="tablist", role="tab", aria-selected) for basic accessibility, especially for the tab headers.

Acceptance criteria

  • All tab headers provided in the items prop are rendered.
  • The content of the first tab is displayed when the component initially loads.
  • Clicking on any inactive tab header makes it the active tab.
  • The content area correctly updates to show the content corresponding to the newly active tab.
  • Only the content of the active tab is visible at any given time.
  • The active tab header is visually distinct from inactive tab headers.
  • The component handles cases where the items array might be empty gracefully (e.g., no tabs or content rendered).

Constraints

Constraints & assumptions

  • You must use React for this problem.
  • All data for the tabs (mockTabItems) is provided directly in App.tsx or passed as props. You do not need to make any API calls.
  • Focus on functional correctness and a clean component structure. Extensive styling is not the primary focus, but basic visual distinction is required.
  • The maximum number of tabs will be small (e.g., 3-5 tabs).
  • Do not use any external UI component libraries for tabs (e.g., Material UI, Ant Design); implement the tab logic yourself.

Out of scope

  • Client-side routing for tabs (e.g., using react-router-dom).
  • Complex animations or transitions between tab content.
  • Saving or restoring tab state across page reloads.
  • Advanced error handling for malformed items data beyond basic checks.

What interviewers evaluate

  • Correct implementation of the tab switching mechanism and dynamic content display.
  • Effective use of React state and props for component management.
  • Clean, readable, and well-structured React code.
  • Adherence to specified UI/UX expectations and acceptance criteria, including basic accessibility considerations.

Loading editor...