useViraPassword()
One hook for the input and its toggle; strength and confirmation are options of the same hook.
Basic usage
Options
| Option | Default | Description |
|---|---|---|
defaultVisible | false | Initial visibility (uncontrolled) |
visible | - | Controlled visibility |
onVisibleChange | - | (visible) => void; also called on automatic hiding |
hideOnSubmit | true | Hide when the form is submitted or reset |
hideOnBlur | false | Hide when focus leaves the field or the tab is hidden |
autoComplete | current-password | new-password with policy or matchWith; false leaves it out |
policy | - | A policy from definePolicy(); enables strength and issues |
forbidden | - | Values the password must not contain (email, name) |
matchWith | - | The password a confirm field repeats; enables matches |
value | - | Current value, e.g. from useWatch() |
icons | Eye / EyeOff | { show, hide } as ReactNode |
disabled | false | Locks the input and the toggle |
readOnly | false | Read-only input, disabled toggle |
id | useId() | Input id; the button's aria-controls |
inputProps | - | Merged into the input props, e.g. register("password") |
btnProps | - | Merged into the button props |
Strength: strength. Confirm field: confirm password.
Return value
| Field | Description |
|---|---|
inputProps | <input {...inputProps} />; attributes only, no ref or handlers |
btnProps | <button {...btnProps} />, icon as children |
isVisible | Current visibility |
toggle() / setVisible(v) | Change visibility (no-op while disabled or readOnly) |
capsLock | Caps Lock is on while the input has focus |
strength | evaluate() result for the current value, or null without a policy |
strengthProps | Live region props for the element that shows strength |
matches | true / false with matchWith; null while empty |
issues | Error keys: policy issues, then password.mismatch |
rule | { validate } for React Hook Form; returns the first key |
Prop merging
Your inputProps and btnProps are applied after the hook's, so most keys can be overridden. These are combined instead:
useViraPassword({
inputProps: { onBlur: () => track("blur"), className: "pr-10" },
})
// onBlur: the hook's handler runs first, then yours
// className, aria-describedby: joined with a space
// ref (your own): passed throughThe returned inputProps holds attributes only, so it can be spread before or after register() or a ViraStack Mask field without replacing their ref or handlers.