Advanced Dual-Thumb Range Slider for Vehicle Configuration
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.
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.
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", "$").Dual-Thumb Interaction: Implement dragging functionality for both the left and right thumbs.
step increment.Keyboard Accessibility: Ensure both thumbs are controllable via keyboard:
step.min/max boundary (respecting the other thumb's position).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.
Visual Feedback: Provide visual distinction for the active (focused or being dragged) thumb. Highlight the selected range section of the track.
role, aria-valuenow, aria-valuemin, aria-valuemax) for the thumbs.RangeSlider component renders correctly with initialMinValue and initialMaxValue.step.onChange callback is triggered with the correct minValue and maxValue upon user interaction.unit prop is correctly displayed with the values.Constraints
min and max values are inclusive. step will always be a positive number.initialMinValue and initialMaxValue will always be within the min and max bounds and initialMinValue <= initialMaxValue.role and aria-* attributes are sufficient).onChange callback for performance optimization (unless explicitly requested or if performance becomes an issue).Loading editor...