Question presented to candidate: "On our product listing page we need a price filter: one track, two handles, a minimum and a maximum. Users drag either handle, or type exact numbers in two boxes. The handles must never cross, values snap to a step, and the product count updates as they move. Build the slider component and a small page that uses it."
Requirements:
- One track from
mintomax(0 to 1000 here) with two handles; values snap tostep(10). - The low handle can never pass the high handle; a minimum gap (
minGap, 50) is kept between them. - The selected part of the track is highlighted.
- Two number boxes show the values and accept typed input, committed on Enter or blur, then snapped and clamped.
- Both handles work with the keyboard (arrows, Home, End) and are announced with names and dollar values.
- The component is controlled: the parent owns
[min, max]and filters a (local, in-memory) product list by it.
What a strong answer should cover:
- The build choice: two stacked native
input type="range"elements (free keyboard and ARIA support) versus a custom pointer-event slider (full control), and the CSS that makes stacking work:pointer-events: noneon the inputs,autoon the thumbs. - Pure helpers for snapping, clamping and value-to-percent mapping.
- Why a clamped handle can stay visually crossed in some frameworks, and how to put it back.
- The stacking problem when both thumbs sit at one end, and the z-index rule that fixes it.
- A draft state for the number boxes so typing does not move the handles keystroke by keystroke.
- What jsdom can and cannot verify, and testing the drag in a real browser.
Clarifying questions expected:
- "Can the two handles meet, or is a minimum gap required?"
- "Should the product list update while dragging, or only on release?"
- "Is the scale linear, or do we need a logarithmic scale for wide price ranges?"
Code / implementation expected: Yes. A working two-handle slider with clamping, snapping, number boxes, keyboard support and a filtered result count.