Fragiola

API: components

PasswordInput

A password field whose text a toggle button shows and hides, keeping the focus and the caret, as a form control, in each framework.

A password text field with a button that shows and hides what was typed: a sign-in form, a new password, a recovery key. The Input is a native <input> whose type switches between password and text; the VisibilityTrigger is the APG's toggle button (button pattern). It is a form control: the Input carries the name, submits, resets and validates, alone or in a Field. The APG has no password pattern and Base UI no PasswordInput: the rest follows Zag/Ark's PasswordInput and Radix's PasswordToggleField. It does not measure the password's strength (a Meter or styled UI).

Sign-in form
Gallery

Behaviour

  • The trigger is a toggle button: aria-pressed tells whether the text is shown and aria-controls names the Input; its name is the app's and never changes ("Show password").
  • Focus and caret: a pointer press on the trigger does not take the focus from the Input (its mousedown's default is prevented), and the Input's selection is put back after its type changes, so the user goes on typing where they were; a keyboard press keeps the focus on the trigger.
  • Forms: the Input is the form control (no hidden input). A form submission hides the text again before the browser reads the form (a browser must not remember it as plain text); a reset returns the text and the visibility to their defaults (reason none).
  • Read-only: the trigger still shows and hides the text; disabled: the Input and the trigger are disabled.
  • In a Field: the Input is the labelable and the validated element (aria-labelledby, aria-describedby, aria-invalid); validate gets the text.
  • Reasons: input-change (typing), trigger-press (the trigger), none (a submission or a reset).

Anatomy

partelementdata-primitives-partrole
Rootdivpassword-input-rootnone; holds the text and the visibility
Inputinputpassword-input-inputtype="password" (no role), or a textbox while shown
VisibilityTriggerbuttonpassword-input-visibility-triggera toggle button

Usage

import { PasswordInput } from "@fragiola/primitives-react/password-input";

<label htmlFor="password">Password</label>
<PasswordInput.Root id="password" name="password" required>
    <PasswordInput.Input autoComplete="current-password" />
    <PasswordInput.VisibilityTrigger aria-label="Show password">
        <EyeIcon />
    </PasswordInput.VisibilityTrigger>
</PasswordInput.Root>;

Props

Every part also takes what the primitive contract gives: render (Vue: as and the render slot), a class and a style, a ref, and any attribute, which it forwards (the Input: autoComplete, minLength, placeholder). The names below are React's; Vue binds them the same way (v-model:value, v-model:visible, @value-change, @visible-change), and Angular as inputs and outputs ([(value)], [(visible)], (valueChangeDetails) and (visibleChangeDetails), each with { value, details } or { visible, details }).

Root

proptypedefaultdescription
valuestringthe text, controlled
defaultValuestring""the initial text, uncontrolled
onValueChange(value: string, details: { reason }) => voidevery change of the text
visiblebooleanwhether the text is shown, controlled
defaultVisiblebooleanfalsethe initial visibility, uncontrolled
onVisibleChange(visible: boolean, details: { reason }) => voidevery change of the visibility
disabledbooleanfalsedisables the Input and the trigger
readOnlybooleanfalsethe Input is read-only; the trigger still works
requiredbooleanfalsethe Input is required
namestringthe Input's name (a Field's wins)
idstringthe Input's id (generated when not given)

Input

No props of its own.

VisibilityTrigger

No props of its own.

State and part attributes

partattributes
every partdata-visible while shown, data-disabled, data-readonly, data-required
Rootin a Field, the field's states
Inputtype ("password" or "text"), autocapitalize="off", spellcheck="false", disabled, readonly, required; in a Field, aria-labelledby, aria-describedby, aria-invalid
VisibilityTriggertype="button", aria-pressed, aria-controls (the Input's id), disabled

Keyboard

keyaction
Tabthe Input, then the trigger
Enter, Space (on the trigger)shows or hides the text; the focus stays on the trigger
Enter (in the Input)the browser's: submits the form

Exports

entryexports
@fragiola/primitives-react/password-inputChangeDetails, ChangeReason, PasswordInput, PasswordInputInputProps, PasswordInputRootProps, PasswordInputState, PasswordInputVisibilityTriggerProps, RenderProp
@fragiola/primitives-vue/password-inputChangeDetails, ChangeReason, PasswordInput, PasswordInputRootEmits, PasswordInputRootProps, PasswordInputState, RenderSlotProps
@fragiola/primitives-angular/password-inputChangeDetails, ChangeReason, PasswordInputInput, PasswordInputRoot, PasswordInputState, PasswordInputVisibilityTrigger, PasswordInputVisibleChangeEvent, ValueChangeEvent