Search docs

Password Input

Password field with a visibility toggle button.

Password Input uses a native <input> whose type switches between "password" and "text", paired with a native <button type="button"> toggle exposing aria-pressed and aria-controls.

import { component$, useStyles$ } from '@builder.io/qwik';
import { PasswordInput } from '@leve-ui/password-input';
import { LuEye, LuEyeOff } from '@qwikest/icons/lucide';
import styles from './default.css?inline';

export default component$(() => {
  useStyles$(styles);

  return (
    <PasswordInput.Root class="password-input-default">
      <PasswordInput.Input
        class="password-input-default-input"
        aria-label="Password"
        placeholder="Enter password"
      />
      <PasswordInput.VisibilityTrigger
        class="password-input-default-trigger"
        aria-label="Toggle password visibility"
      >
        <PasswordInput.Indicator class="password-input-default-indicator">
          <LuEye class="password-input-default-icon-show" aria-hidden="true" />
          <LuEyeOff class="password-input-default-icon-hide" aria-hidden="true" />
        </PasswordInput.Indicator>
      </PasswordInput.VisibilityTrigger>
    </PasswordInput.Root>
  );
});

Installation#

Install the individual package, or use @leve-ui/core to get every component at once:

pnpm add @leve-ui/password-input

Anatomy#

import { PasswordInput } from '@leve-ui/password-input'; // or '@leve-ui/core'

<PasswordInput.Root>
  <PasswordInput.Input />
  <PasswordInput.VisibilityTrigger>
    <PasswordInput.Indicator />
  </PasswordInput.VisibilityTrigger>
</PasswordInput.Root>
PartElementDescription
PasswordInput.Root<div>Wraps the parts and holds the visibility state. Not interactive.
PasswordInput.Input<input>The password input whose type toggles between "password" and "text".
PasswordInput.VisibilityTrigger<button>Button that toggles password visibility (aria-pressed, aria-controls).
PasswordInput.Indicator<span>Decorative container for visibility icons (aria-hidden="true").

Examples#

Default Visible#

defaultVisible shows the password initially.

Controlled#

Control the visibility state with bind:visible.

Visibility: hidden

Disabled#

disabled on the Root disables both the input and the visibility trigger.

With Field#

Inside a Field.Root, Field.Label, Field.Description, Field.ErrorMessage, and the disabled / readOnly / required / invalid states are wired automatically.

Must be at least 8 characters.

API Reference#

Root#

PropDefaultType
ids–{ input?: string }

Overrides the element IDs of the parts. Only used outside a Field.

defaultVisiblefalseboolean

The initial visibility state of the password (uncontrolled).

bind:visible–Signal<boolean>

A signal with the visibility state (controlled).

onVisibleChange$–QRL<(visible: boolean) => void>

Called when the visibility state changes.

disabledfalseboolean

Disables the password input and its visibility trigger. Inside a Field, the Field's disabled also applies.

readOnlyfalseboolean

Marks the password input as read-only. Inside a Field, the Field's readOnly also applies.

requiredfalseboolean

Marks the password input as required. Inside a Field, the Field's required also applies.

invalidfalseboolean

Marks the password input as invalid. Inside a Field, the Field's invalid also applies.

Also accepts all <div> attributes.

Data attributeValue
data-leve-password-inputAlways present
data-state"visible" | "hidden"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

The visibility state is uncontrolled with defaultVisible, or controlled with bind:visible. onVisibleChange$ is called when the visibility changes.

Inside a Field, the input ID comes from the Field and ids is ignored (ADR 0024).

Input#

PropDefaultType
bind:value–Signal<string>

A signal bound to the input value.

Also accepts all <input> attributes.

Data attributeValue
data-leve-password-input-inputAlways present
data-state"visible" | "hidden"
data-disabledPresent when disabled
data-readonlyPresent when read-only
data-invalidPresent when invalid

VisibilityTrigger#

No props of its own. Accepts all <button> attributes.

Data attributeValue
data-leve-password-input-visibility-triggerAlways present
data-state"visible" | "hidden"
data-disabledPresent when disabled

Indicator#

No props of its own. Accepts all <span> attributes.

Data attributeValue
data-leve-password-input-indicatorAlways present
data-state"visible" | "hidden"
data-disabledPresent when disabled

Accessibility#

Uses native HTML <input> and <button type="button"> elements.

  • Provide an accessible name for PasswordInput.Input via Field.Label, aria-label, or aria-labelledby.
  • Provide an accessible name for PasswordInput.VisibilityTrigger via aria-label or visible button text.
  • PasswordInput.VisibilityTrigger outputs aria-controls pointing to PasswordInput.Input and aria-pressed ("true" or "false").
  • PasswordInput.Indicator is hidden from assistive technologies with aria-hidden="true".

Keyboard Interactions#

KeyDescription
SpaceToggles password visibility when VisibilityTrigger is focused.
EnterToggles password visibility when VisibilityTrigger is focused (submits form when Input is focused inside a <form>).