Question presented to candidate: "Our sign-in form gets a lot of support tickets from people who mistype their password. Build a password field with a Show / Hide button next to it, so users can check what they typed. It has to be accessible and it must not make the password less safe. If you have time, warn the user when Caps Lock is on."
Requirements:
- A labelled password input with a toggle button that switches between hidden and visible text.
- The button says Show or Hide, has an accessible name ("Show password" / "Hide password") and must never submit the form.
- Screen reader users are told when the password becomes visible or hidden.
- A "Caps Lock is on" hint while typing with Caps Lock enabled.
- When the form is submitted the password is hidden again; the value is never lost when toggling.
What a strong answer should cover:
- The only way to reveal a password is switching the input
typebetweenpasswordandtext; one boolean of state drives it. type="button"on the toggle,aria-controls, a changing accessible name (oraria-pressed, but not both), and a polite live region announcement.- Security details:
autocomplete="current-password",spellcheck="false"andautocapitalize="none", and switching back totype="password"on submit. - Caps Lock detection with
KeyboardEvent.getModifierState("CapsLock")on key events. - Keeping focus and the typed value stable when the type changes.
Clarifying questions expected:
- "Is this a sign-in field (current password) or a new-password field with strength rules?"
- "Should the password re-hide on its own after a few seconds, or only on submit?"
Code / implementation expected: Yes. A reusable password input component used inside a small sign-in form, in the framework of your choice.