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.The controlled visibility state of the password.
The visibility state when initially rendered (uncontrolled).
Event handler called when the visibility state changes.
When true, prevents the user from interacting with the field.
Change the default rendered element for the one passed as a child.
Input
The password input element.The name of the input. Submitted with its owning form as part of a name/value pair.
The controlled value of the input.
The value when initially rendered (uncontrolled).
Event handler called when the input value changes.
When true, indicates that the user must fill the input before submitting the form.
Hint for form autofill feature. Common values: “current-password”, “new-password”.
Change the default rendered element for the one passed as a child.
Toggle
The button that toggles password visibility.Change the default rendered element for the one passed as a child.
Icon
Renders the appropriate icon based on visibility state.Used to force mounting when more control is needed.
Change the default rendered element for the one passed as a child.
Slot
A slot for custom content that changes based on visibility state.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
[data-visible]- Present when password is visible[data-disabled]- Present when disabled
[data-visible]- Present when password is visible