Password Input

A component that allows users to enter secure text like (passwords and api keys)

Loading...

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.

AttributeDefaultType
asChild
boolean

Use 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
boolean

The default visibility of the password input.

disabled
boolean

Whether the password input is disabled.

id
string

The unique identifier of the machine.

ids
ElementIds

The ids of the password input parts

ignorePasswordManagers
boolean

When `true`, the input will ignore password managers. **Only works for the following password managers** - 1Password, LastPass, Bitwarden, Dashlane, Proton Pass

invalid
boolean

The invalid state of the password input.

name
string

The name of the password input.

onVisibilityChange
(details: VisibilityChangeDetails) => void

Function called when the visibility changes.

readOnly
boolean

Whether 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
boolean

Whether the password input is required.

translations
IntlTranslations

The localized messages to use.

visible
boolean

Whether the password input is visible.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[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.

AttributeDefaultType
value
UsePasswordInputReturn

asChild
boolean

Use 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.

AttributeDefaultType
asChild
boolean

Use 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.

AttributeDescription
[data-password-input-visibility-trigger]<uid>
[data-readonly]Present when read-only
[data-disabled]Present when disabled
[data-state]"visible" | "hidden"

Context

API

PropertyType
visible
boolean

Whether the password input is visible.

disabled
boolean

Whether the password input is disabled.

invalid
boolean

Whether the password input is invalid.

focus
VoidFunction

Focus the password input.

setVisible
(value: boolean) => void

Set the visibility of the password input.

toggleVisible
VoidFunction

Toggle the visibility of the password input.

getRootState
() => RootState

Returns the state of the root. Every part shares it.