Skip to main content

Overview

Password Toggle Field provides an enhanced password input with a built-in toggle button to switch between hiding and showing the password text. This improves usability by allowing users to verify their input.

Features

  • Toggle visibility of password text
  • Custom icons for show/hide states
  • Full keyboard navigation
  • Works inside forms
  • Can be controlled or uncontrolled
  • Accessible by default with proper ARIA attributes

Installation

Anatomy

API Reference

Root

Contains all the password field parts.
boolean
The controlled visibility state of the password.
boolean
default:"false"
The visibility state when initially rendered (uncontrolled).
(visible: boolean) => void
Event handler called when the visibility state changes.
boolean
When true, prevents the user from interacting with the field.
boolean
default:"false"
Change the default rendered element for the one passed as a child.

Input

The password input element.
string
The name of the input. Submitted with its owning form as part of a name/value pair.
string
The controlled value of the input.
string
The value when initially rendered (uncontrolled).
(event: React.ChangeEvent<HTMLInputElement>) => void
Event handler called when the input value changes.
boolean
When true, indicates that the user must fill the input before submitting the form.
string
Hint for form autofill feature. Common values: “current-password”, “new-password”.
boolean
default:"false"
Change the default rendered element for the one passed as a child.

Toggle

The button that toggles password visibility.
boolean
default:"false"
Change the default rendered element for the one passed as a child.

Icon

Renders the appropriate icon based on visibility state.
boolean
Used to force mounting when more control is needed.
boolean
default:"false"
Change the default rendered element for the one passed as a child.

Slot

A slot for custom content that changes based on visibility state.
boolean
default:"false"
Change the default rendered element for the one passed as a child.

Example

Accessibility

The toggle button includes proper ARIA attributes to announce the visibility state to screen readers.

Keyboard Interactions

  • Tab - Moves focus between the input and toggle button.
  • Space/Enter - When toggle is focused, toggles password visibility.

Features

  • Input type automatically switches between “password” and “text”
  • Toggle button is properly labeled for screen readers
  • Visibility state is announced when changed
  • Supports all standard input attributes

Data Attributes

Root
  • [data-visible] - Present when password is visible
  • [data-disabled] - Present when disabled
Toggle
  • [data-visible] - Present when password is visible
  • [data-disabled] - Present when disabled
Icon
  • [data-visible] - Present when password is visible