Range SliderLoading saved progress…

Range Slider

A dual-handle range slider lets someone choose the lower and upper bounds of an interval on one track. Build it as a React component with pointer and keyboard input, integer values from 0 to 100, a highlighted segment, and a label that always reflects the ordered range.

Signature

Implement the App component in App.tsx. It receives no props and renders two focusable slider handles whose low and high values start at 20 and 80.

Examples

  • The page loads with handles at 20 and 80, a green bar between them, and 20 – 80 below. Dragging the left handle right to the middle updates the label to 50 – 80 and shrinks the green bar.
  • Dragging the left handle past the right one clamps it: it stops at 80, never overtaking the high handle.
  • Releasing the pointer anywhere (even off the handle) ends the drag, because the listeners live on window.
  • Focusing the high handle and pressing ArrowLeft changes 20 – 80 to 20 – 79; pressing Home stops it at the low value, 20.

Notes

  • React state. Keep low and high in useState, and read the track through a useRef.
  • Window listeners. Start pointermove and pointerup listeners on window, then remove both on release so fast drags keep tracking without leaking handlers.
  • Integer values. Convert X with Math.round((clientX - left) / width * 100) and clamp the result to 0..100.
  • Ordered handles. Clamp each update against the other value so low <= high always holds.
  • Keyboard behavior. Make each role="slider" focusable; Arrow keys move by one, Home moves to its allowed minimum, and End moves to its allowed maximum.
  • Starting shell. The track, fill, handles, label, and visual CSS are provided. Keep aria-valuenow and each handle's live ARIA boundary synchronized with state.
WE’RE LISTENING

Help make UIReady better

Found a bug or have an idea? Tell us about it.

Up to 3 files · 5 MiB each · JPG, PNG, WebP, MP4, WebM, MP3, M4A or WAV