Password Input
A component that allows users to enter secure text like (passwords and api keys)
Anatomy
<PasswordInput.Root>
<PasswordInput.Label />
<PasswordInput.Control>
<PasswordInput.Input />
<PasswordInput.VisibilityTrigger>
<PasswordInput.Indicator />
</PasswordInput.VisibilityTrigger>
</PasswordInput.Control>
</PasswordInput.Root>
Examples
Autocomplete
Set autoComplete to control autocompletion:
new-password: the user is creating a new password.current-password: the user is entering an existing password.
Controlled Visibility
Use visible and onVisibilityChange to control visibility.
Root Provider
Use RootProvider with the usePasswordInput hook to access the state and methods from outside the component.
Field
Password Managers
Set ignorePasswordManager for non-login fields like API keys, secure notes or temporary passwords.
Only works for 1Password, LastPass, Bitwarden, Dashlane and Proton Pass.
Strength Meter
Pair with a strength library to show live feedback. This example uses
check-password-strength.
Validation
Set invalid to flag errors from your own validation logic.
API Reference
Props
Root
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
autoComplete | 'current-password' | 'current-password' | 'new-password'The autocomplete attribute for the password input. |
defaultVisible | booleanThe default visibility of the password input. | |
disabled | booleanWhether the password input is disabled. | |
id | stringThe unique identifier of the machine. | |
ids | ElementIdsThe ids of the password input parts | |
ignorePasswordManagers | booleanWhen `true`, the input will ignore password managers. **Only works for the following password managers** - 1Password, LastPass, Bitwarden, Dashlane, Proton Pass | |
invalid | booleanThe invalid state of the password input. | |
name | stringThe name of the password input. | |
onVisibilityChange | (details: VisibilityChangeDetails) => voidFunction called when the visibility changes. | |
readOnly | booleanWhether the password input is read only. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<PasswordInputRootState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. | |
required | booleanWhether the password input is required. | |
translations | IntlTranslationsThe localized messages to use. | |
visible | booleanWhether the password input is visible. |
| Attribute | Description |
|---|---|
[data-password-input-root] | <uid> |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-readonly] | Present when read-only |
Control
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-password-input-control] | <uid> |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-readonly] | Present when read-only |
Indicator
Defines the <span> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
fallback | string | number | bigint | boolean | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode> | ReactPortal | Promise<...>The fallback content to display when the password is not visible. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-password-input-indicator] | <uid> |
[data-state] | "visible" | "hidden" |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-readonly] | Present when read-only |
Input
Defines the <input> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<PasswordInputInputState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-password-input-input] | <uid> |
[data-state] | "visible" | "hidden" |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-readonly] | Present when read-only |
Label
Defines the <label> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<EmptyState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-password-input-label] | <uid> |
[data-disabled] | Present when disabled |
[data-invalid] | Present when invalid |
[data-readonly] | Present when read-only |
[data-required] | Present when required |
RootProvider
Defines the <div> element.
| Attribute | Default | Type |
|---|---|---|
value | UsePasswordInputReturn | |
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | type ONLY_FOR_FORMAT =
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<PasswordInputRootProviderState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
VisibilityTrigger
Defines the <button> element.
| Attribute | Default | Type |
|---|---|---|
asChild | booleanUse the provided child element as the default rendered element, combining their props and behavior. Use `render` when you need the part's state: `render={(props, state) => <MyButton {...props} />}`. For more details, read our Composition guide. | |
render | type ONLY_FOR_FORMAT =
ReactElement<unknown, string | JSXElementConstructor<any>> | RenderFn<PasswordInputVisibilityTriggerState>Render the part as a custom element, combining their props and behavior. Pass an element to have the part's props merged into it, or a function to control the merge yourself and read the part's state. |
| Attribute | Description |
|---|---|
[data-password-input-visibility-trigger] | <uid> |
[data-readonly] | Present when read-only |
[data-disabled] | Present when disabled |
[data-state] | "visible" | "hidden" |
Context
API
| Property | Type |
|---|---|
visible | booleanWhether the password input is visible. |
disabled | booleanWhether the password input is disabled. |
invalid | booleanWhether the password input is invalid. |
focus | VoidFunctionFocus the password input. |
setVisible | (value: boolean) => voidSet the visibility of the password input. |
toggleVisible | VoidFunctionToggle the visibility of the password input. |
getRootState | () => RootStateReturns the state of the root. Every part shares it. |