Accessibility
ARIA, focus after a click, a live region for strength and Caps Lock.
ARIA attributes
<input id="virapassword-input-:r0:" type="password" aria-describedby="…-strength" />
<button
type="button"
aria-label="Toggle password visibility"
aria-pressed="false"
aria-controls="virapassword-input-:r0:"
/>type="button": the toggle never submits the form.aria-pressedtells screen readers whether the password is shown;aria-controlslinks the button to the input.- The label is in English; translate it through btnProps:
useViraPassword({ btnProps: { "aria-label": t("togglePassword") } })Focus
- A mouse or touch press returns focus and the caret to the input.
- Enter or Space on the focused button keeps focus on the button.
- Safari skips buttons on Tab unless "Tab to all controls" is on; Option+Tab reaches them. That's a browser setting, not a bug.
Live region
Spread strengthProps on the element that shows strength. Announce a short level, not every rule, so typing isn't noisy.
const { inputProps, strength, strengthProps } = useViraPassword({ policy })
<input {...inputProps} />
<p {...strengthProps}>{strength?.level}</p>
// role="status" aria-live="polite" aria-atomic="true"
// the input gets aria-describedby pointing at itCaps Lock
capsLock is true while Caps Lock is on and the input has focus. Show a text hint; colour alone isn't enough.
Stable IDs
Without id, the input gets one from useId(), which matches between server and client. Pass id when a label or test needs a fixed value.