Question presented to candidate: "Build a small Kanban board: three columns, To Do, In Progress and Done, each with a few cards. I want to drag a card to another column or to a new spot in the same column, and add new cards. Users who cannot use a mouse must be able to move cards too. You have about 45 minutes, no libraries."
Requirements:
- Three columns of cards; dragging a card onto another card inserts it before that card, dropping on empty space appends it.
- Reordering inside one column works, and dropping a card where it already is changes nothing.
- A visible drop indicator while dragging, and the dragged card looks picked up.
- A keyboard path: focus a card, Space to pick it up, arrow keys to move it between and within columns, Space to drop, Escape to cancel.
- Screen-reader announcements for pick up, move, drop and cancel.
- An add-card form per column.
What a strong answer should cover:
- A normalised state model (columns hold ordered card ids, cards live in a lookup) and one pure
moveCardfunction used by both mouse and keyboard. - The HTML5 drag-and-drop contract:
draggable,dragstartwithdataTransfer.setData,preventDefault()indragoverto allow a drop,drop, anddragendfor cleanup. - The index off-by-one when moving down inside the same column, and the no-op case.
- Why focus is lost when a card changes column (a new DOM node) and how to restore it after render.
- Accessibility:
aria-roledescription,aria-pressedfor the picked-up card, a polite live region, focus-visible styles. - Avoiding re-render storms:
dragoverfires many times a second, so only update hover state when the target changes.
Clarifying questions expected:
- "Do cards need to persist (server or localStorage), or is in-memory fine?"
- "Is touch support required? HTML5 drag and drop behaves inconsistently on touch devices, which may mean pointer events instead."
- "Do columns have limits or rules about which moves are allowed?"
Code / implementation expected: Yes. A working board in the chosen framework with the pure move function, drag handlers, the keyboard mode and the live region.