Frontend School

Dynamic Breadcrumbs Component for Ola Rides

Machine Coding
medium

Dynamic Breadcrumbs Component for Ola Rides

Medium
Frontend
React
UI
Breadcrumbs
Component Design

Overview

In a complex application like Ola, users navigate through various screens and flows, from booking a ride to reviewing past trips or managing profiles. A clear navigational aid is crucial for a smooth user experience. Breadcrumbs provide users with a visual trail of their location within the application's hierarchy, enhancing discoverability and allowing them to quickly jump back to previous sections. This problem focuses on building a robust and reusable Breadcrumbs component.

What you need to do / Task

Your task is to implement a Breadcrumbs React component that dynamically renders a navigation trail based on an array of path objects.

  1. Create a Breadcrumbs component: This component should accept a prop, paths, which is an array of objects. Each object in the paths array should have at least a label (string) and an optional path (string) representing the URL segment.
    interface BreadcrumbItem {
      label: string;
      path?: string; // Optional path for the last item, or if it's not meant to be a link
    }
    
  2. Render the breadcrumbs: Iterate through the paths array and render each item.
  3. Handle the last item: The last item in the breadcrumb trail should be displayed as plain text and should not be a clickable link, as it represents the current page.
  4. Separator: Display a consistent separator (e.g., >) between breadcrumb items.
  5. Dynamic updates: Ensure the component correctly re-renders when the paths prop changes.

UI/UX expectations

  • Layout: Breadcrumbs should be displayed horizontally, typically at the top of a content area.
  • Interactions: Each breadcrumb item (except the last) should be a clickable link. Clicking it should conceptually navigate to the specified path (you don't need to implement actual routing, just use <a> tags).
  • Accessibility: Use semantic HTML elements (e.g., <nav>, <ol>, <li>) and consider ARIA attributes where appropriate to enhance accessibility for screen readers.
  • Basic Styling: Apply minimal styling to distinguish links from plain text and to display the separator clearly.

Acceptance criteria

  • The Breadcrumbs component renders correctly based on the paths prop.
  • The last item in the breadcrumb trail is displayed as text and is not a clickable link.
  • All other items are rendered as clickable links, using their path property.
  • A visible separator (e.g., >) is present between successive breadcrumb items.
  • The component updates and re-renders correctly when the paths prop is changed dynamically.
  • The component uses semantic HTML for navigation.

Constraints

Constraints & assumptions

  • The paths array prop will always contain at least one BreadcrumbItem.
  • The path property for BreadcrumbItem will be a simple string (e.g., /home, /rides/current/details). You do not need to implement complex routing logic; simply use standard <a> tags.
  • Maximum number of breadcrumb items will not exceed 5-7.
  • You are free to use functional components and React Hooks.
  • No need for external UI libraries.

Out of scope

  • Integration with a specific routing library (e.g., React Router, Next.js Router).
  • Complex error handling for malformed paths data.
  • Advanced theming or highly customized styling beyond basic visual distinction.
  • Implementing actual page navigation logic on link clicks.

What interviewers evaluate

  • Component Design: Clarity, reusability, and maintainability of the Breadcrumbs component.
  • Correctness: Accurate rendering of breadcrumb items, handling of the last item, and separator display.
  • Dynamic Behavior: Proper handling of prop updates and component re-rendering.
  • HTML Semantics & Accessibility: Use of appropriate HTML elements and basic accessibility considerations.
  • Code Quality: Readability, organization, and adherence to best practices.

Loading editor...