Frontend School

Advanced Dual-Thumb Range Slider for Vehicle Configuration

Machine Coding
hard

Advanced Dual-Thumb Range Slider for Vehicle Configuration

Hard
React
TypeScript
UI/UX
Accessibility
Range Slider
Machine Coding

Overview

At Tesla, vehicle configuration involves a multitude of dynamic adjustments, from battery range settings to charging limits and performance parameters. A highly interactive and robust range slider is a fundamental UI component for allowing users to intuitively select a desired interval within a given spectrum. This problem challenges you to build a production-grade dual-thumb range slider, mirroring the precision and user experience expected in our vehicle configuration interfaces.

What you need to do / Task

Your primary task is to implement a reusable RangeSlider React component that allows a user to select a range between two values using two draggable thumbs.

  1. Component Definition: Create a RangeSlider component that accepts the following props:

    • min: number: The minimum possible value for the slider.
    • max: number: The maximum possible value for the slider.
    • step: number: The increment/decrement step for values. Must be greater than 0.
    • initialMinValue: number: The initial position of the left thumb.
    • initialMaxValue: number: The initial position of the right thumb.
    • onChange: (min: number, max: number) => void: A callback function that fires when the selected range changes.
    • unit?: string: An optional string to display as a suffix for the values (e.g., "mi", "$").
  2. Dual-Thumb Interaction: Implement dragging functionality for both the left and right thumbs.

    • Thumbs should move smoothly along the track.
    • The left thumb cannot cross the right thumb, and vice-versa.
    • Values should snap to the nearest step increment.
  3. Keyboard Accessibility: Ensure both thumbs are controllable via keyboard:

    • When a thumb is focused, arrow keys (left/right or up/down) should move it by one step.
    • Home/End keys should move the thumb to its respective min/max boundary (respecting the other thumb's position).
  4. Value Display: Clearly display the currently selected minValue and maxValue to the user, ideally near the thumbs or above the slider. Include the unit if provided.

  5. Visual Feedback: Provide visual distinction for the active (focused or being dragged) thumb. Highlight the selected range section of the track.

UI/UX expectations

  • The slider should consist of a track, two distinct thumbs, and a visual representation of the selected range between the thumbs.
  • Values should be displayed in an accessible and readable manner.
  • Interactions (dragging, keyboard) should feel responsive and intuitive.
  • Consider basic accessibility attributes (e.g., role, aria-valuenow, aria-valuemin, aria-valuemax) for the thumbs.
  • The component should be reasonably responsive to different container widths (basic fluid layout).

Acceptance criteria

  • The RangeSlider component renders correctly with initialMinValue and initialMaxValue.
  • Dragging either thumb updates its position and the displayed values correctly.
  • Thumbs cannot be dragged past each other.
  • Dragging snaps values to the nearest step.
  • Keyboard navigation (arrow keys, Home/End) correctly moves focused thumbs and updates values.
  • The onChange callback is triggered with the correct minValue and maxValue upon user interaction.
  • The unit prop is correctly displayed with the values.
  • The selected range on the track is visually distinct.
  • Basic accessibility attributes are present on interactive elements.

Constraints

Constraints & assumptions

  • You must use React and TypeScript.
  • Do not use any external UI component libraries (e.g., Material UI, Ant Design). Build the slider from scratch using native HTML elements and CSS.
  • Focus on the core functionality; extensive styling beyond basic layout and visual feedback is not required.
  • The min and max values are inclusive. step will always be a positive number.
  • Assume the initialMinValue and initialMaxValue will always be within the min and max bounds and initialMinValue <= initialMaxValue.
  • Performance for smooth dragging is expected.

Out of scope

  • Extensive cross-browser compatibility testing beyond modern browsers.
  • Full ARIA accessibility audit (basic role and aria-* attributes are sufficient).
  • Form submission integration or validation logic.
  • Debouncing or throttling the onChange callback for performance optimization (unless explicitly requested or if performance becomes an issue).

What interviewers evaluate

  • Correctness and Robustness: Accuracy of the range slider logic, handling edge cases (e.g., thumb crossing, snapping to step).
  • Component Design & State Management: Clean, modular, and reusable React component structure, effective use of hooks for state and side effects.
  • Interaction & UI/UX: Smooth and intuitive user experience for both mouse and keyboard interactions, clear visual feedback.
  • TypeScript & Code Quality: Appropriate use of TypeScript for type safety, clean code, readability, and maintainability.
  • Accessibility Foundations: Implementation of fundamental accessibility practices for interactive UI components.

Loading editor...