All practice tasks

Coding (Platform)

Dialog focus restoration contract

react · Easy · focus management

A React dialog can close because the user confirms, cancels, presses Escape, or the trigger disappears after navigation. The current reducer always restores focus to the original trigger, including when it is no longer mounted.

Task

Choose one safe focus target from the close reason and the currently mounted element IDs.

Contract

Input is {triggerId,fallbackId,closeReason,mountedIds}. Return {focusId,announce}. Prefer a mounted trigger, then a mounted fallback, otherwise null.

Acceptance criteria

  • Never return an unmounted element.
  • Use the same target for confirm, cancel and Escape.
  • Return a concise close announcement.
  • Do not make focus depend on object identity.

Constraints

  • Do not mutate caller-owned input.
  • Keep the supplied framework adapter and public contract unchanged.
  • Add candidate tests for at least one boundary not covered by the public cases.

Editable files

  • src/repair.js — Task-specific state or service boundary
  • tests/candidate.test.js — Candidate-authored regression

What this task practices

Dialog focus restoration contract is a coding (platform) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on State Modeling, Regression Testing, Technical Reasoning. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.