Question presented to candidate: "Build a seat picker: a 6 by 8 grid of cells. Pressing on a cell and dragging selects the rectangle between where you started and where you are, like selecting cells in a spreadsheet. Holding Ctrl or Cmd adds the rectangle to the existing selection, or removes it if you start on a selected cell. Show how many cells are selected, and make it usable from the keyboard."
Requirements:
- Press and drag selects the rectangle from the anchor cell to the current cell, in any direction, with a live preview while dragging.
- A plain drag replaces the selection; Ctrl or Cmd adds, or subtracts when the drag starts on a selected cell.
- Nothing is committed until the pointer is released; Escape during a drag cancels it, and
pointercanceldoes too. - Dragging outside the grid keeps selecting up to the nearest edge.
- No text selection while dragging, and it works with touch.
- Keyboard: arrow keys move a single focus through the grid, Shift + arrows extend a rectangle from the anchor, Space toggles a cell, Ctrl + A selects all, Escape clears.
role="grid"witharia-multiselectable,aria-selectedper cell and a live count.
What a strong answer should cover:
- Separating committed selection from the drag in progress, and deriving what is shown from both.
- Mapping pointer coordinates to a cell from the grid box, clamped to the edges, instead of relying on per-cell
mouseenter. - Pointer capture (
setPointerCapture) so moves keep arriving outside the grid and on touch devices. - Only re-rendering when the pointer crosses into a new cell.
- A roving tabindex so the grid is one tab stop.
- Immutable
Setupdates and why they matter for change detection.
Clarifying questions expected:
- "Rectangle selection or freehand painting of every cell the pointer touches?"
- "Should some cells be disabled, such as sold seats?"
- "Is the grid size fixed, or can it be large enough to need virtualisation?"
Code / implementation expected: Yes. The grid component with pointer and keyboard selection.