Frontend School

Interactive Dual-Handle Range Slider

Machine Coding
medium

Interactive Dual-Handle Range Slider

Medium
React
JavaScript
UI
Component
Range Slider
Accessibility
Machine Coding

Overview

Inmobi's ad platform relies heavily on user-friendly interfaces for configuring campaign parameters and analyzing performance data. A common requirement is to allow users to filter or select data within a specific numerical range, such as ad bid amounts, impression counts, or date ranges. A well-implemented range slider enhances the user experience by providing an intuitive visual control for these selections, improving data exploration and configuration efficiency.

What you need to do / Task

Your task is to build a reusable RangeSlider React component that allows users to select a numerical range using two draggable handles.

  1. Implement a Dual-Handle Slider: Create a slider component with two distinct handles, one for the minimum value and one for the maximum value within a given overall range.
  2. Handle User Interaction:
    • Allow users to drag each handle independently to adjust its respective value.
    • Ensure handles cannot cross each other (i.e., min handle cannot go past max handle, and vice versa).
    • Implement keyboard navigation for each handle (left/right arrow keys to decrease/increase its value).
  3. Display Selected Range: Clearly display the currently selected minimum and maximum values above or beside the slider.
  4. Callback on Change: The component should expose an onChange prop that gets called whenever the selected range changes, providing the new [min, max] values.
  5. Basic Styling: Apply minimal styling to make the slider visually distinguishable and interactive.

UI/UX expectations

  • Layout: The slider should consist of a main "track" representing the full possible range. Two "handles" should be positioned on this track, representing the currently selected min and max values.
  • Visual Feedback: The portion of the track between the two handles should be visually distinct (e.g., a different color) to indicate the active selection.
  • Value Display: The current min and max selected values should be displayed as text, updating in real-time as handles are moved.
  • Accessibility: Both handles should be focusable via keyboard (tab key). left and right arrow keys should adjust the focused handle's value. Appropriate ARIA attributes (e.g., role="slider", aria-valuenow, aria-valuemin, aria-valuemax, aria-label) should be used to make the component accessible.

Acceptance criteria

  • The RangeSlider component renders correctly with initial min and max values.
  • Both handles are independently draggable within the overall range.
  • Handles cannot be dragged past each other.
  • The displayed values update accurately as handles are moved.
  • The active range between handles is visually highlighted.
  • Pressing Tab focuses on the handles.
  • Pressing Left Arrow or Right Arrow keys adjusts the focused handle's value by one step.
  • The onChange callback is invoked with the correct [min, max] values when the selection changes.

Constraints

Constraints & assumptions

  • The slider will operate on a continuous numerical range of integers.
  • The overall minimum and maximum values for the slider are provided as props and remain fixed.
  • The component should be built using React.
  • No external UI libraries (e.g., Ant Design, Material UI) are allowed for the slider's core functionality. Basic styling libraries like Tailwind CSS are acceptable if you prefer, but a pure CSS solution is also fine.
  • The slider values should change by 1 unit for keyboard interactions.
  • The target environment is modern web browsers (Chrome, Firefox, Safari, Edge).

Out of scope

  • Complex input validation beyond basic numeric checks.
  • Responsiveness for vastly different screen sizes (basic fluid layout is sufficient).
  • Debouncing onChange calls (call immediately on value change).
  • Support for floating-point numbers or custom step sizes (stick to integers and step 1).

What interviewers evaluate

  • Component Design & State Management: How well the React component is structured, how state is managed for the slider's values and positions, and effective use of hooks.
  • Event Handling & DOM Manipulation: Correct implementation of mouse/touch events for dragging and keyboard events for accessibility, and accurate calculation of handle positions.
  • UI/UX Implementation: Fidelity to the visual and interactive requirements, including the active range highlight and real-time value updates.
  • Code Quality & Readability: Clarity, maintainability, and efficiency of the code, including proper typing with TypeScript.
  • Accessibility (A11y): Consideration for keyboard navigation and appropriate ARIA attributes.

Loading editor...