Question presented to candidate: "Build a reusable combobox for a 'Favourite language' field: the user can type to filter the options or open the full list, move with the keyboard, and select one value. It must follow the WAI-ARIA combobox pattern closely enough that a screen-reader user can use it, and the parent form must be able to read and set the value."
Requirements:
- Controlled component: the parent owns
value(an option id or null) and receives changes; the input shows the selected option's label, and a value set from outside updates the label. - Typing filters options (case-insensitive substring) and highlights the first enabled match automatically; Enter commits it; leaving the field (Tab, click elsewhere) also commits the highlighted match, and with no match the previous label is restored.
- Down / Up open the list (on the selected option, or the first / last) and move with wrap-around, skipping disabled options; Alt+Down opens without highlighting; Escape closes and restores the label, and a second Escape clears the value.
- A toggle button (โพ) and a clear button (ร) that never take focus away from the input; mouse hover highlights, click commits, disabled options cannot be chosen.
- DOM focus always stays in the input; the highlighted option is exposed with
aria-activedescendant; a polite live region announces the number of options.
What a strong answer should cover:
- The difference between the text in the input, the filter, the highlighted (active) option and the committed value, and why they are separate pieces of state.
- The ARIA wiring:
role="combobox",aria-autocomplete="list",aria-expanded,aria-controls,aria-activedescendant,role="listbox"/role="option",aria-selected,aria-disabled, unique stable ids. - A keyboard map for the closed and open states, and the blur rule for "list autocomplete with automatic selection".
mousedownpreventDefaulton options and buttons so focus never leaves the input.- Scrolling the active option into view, and how the component exposes its value (props + callback,
v-model,[(value)]/ControlValueAccessor).
Clarifying questions expected:
- "Must the value be one of the options, or is free text allowed?"
- "Should the first match be highlighted automatically, and should leaving the field commit it?"
- "Are options local or loaded from a server? How many?"
Code / implementation expected: Yes. A reusable, controlled combobox component with full keyboard support and correct ARIA attributes.