Password Input

Password field with a button that shows or hides the password.

React

Built on Ark UI's Password Input. The input shares its sizes and variants with the input recipe, and the visibility trigger sits inside the input's border at the end. Only React has this component so far.

Usage

import { Icon } from "@isbatak/react-ui/icon"
import { PasswordInput } from "@isbatak/react-ui/password-input"

export function PasswordInputDemo() {
  return (
    <PasswordInput.Root maxW="xs">
      <PasswordInput.Label>Password</PasswordInput.Label>
      <PasswordInput.Control>
        <PasswordInput.Input placeholder="Enter your password" />
        <PasswordInput.VisibilityTrigger>
          <PasswordInput.Indicator fallback={<Icon name="view-off" />}>
            <Icon name="view" />
          </PasswordInput.Indicator>
        </PasswordInput.VisibilityTrigger>
      </PasswordInput.Control>
    </PasswordInput.Root>
  )
}
<PasswordInput.Root>
  <PasswordInput.Label />
  <PasswordInput.Control>
    <PasswordInput.Input />
    <PasswordInput.VisibilityTrigger>
      <PasswordInput.Indicator />
    </PasswordInput.VisibilityTrigger>
  </PasswordInput.Control>
</PasswordInput.Root>

PasswordInput.Indicator renders its children while the password shows and its fallback while it is hidden. The icons here are view and view-off from the active sprite, so they follow your own icons.

Examples

Sizes

Set size on the root to xs, sm, md or lg. The default is md.

Variants

Set variant on the root to outline, subtle or flushed. The default is outline.

Default visible

Set defaultVisible to show the password when the input first renders.

Controlled

Pass visible and onVisibilityChange to own whether the password shows.

Password is hidden

Root provider

Create the state with usePasswordInput and pass it to PasswordInput.RootProvider to control the input from outside, here with toggleVisible. The returned API also has setVisible and focus.

Autocomplete

The input sets autocomplete="current-password" by default. Set autoComplete="new-password" on sign-up and change-password forms so browsers offer to generate a password instead of filling a saved one.

Ignore password managers

Set ignorePasswordManagers for secrets that are not login passwords, like API keys, so password managers do not offer to fill or save them. It works with 1Password, LastPass, Bitwarden, Dashlane and Proton Pass.

Disabled

Set disabled on the root to disable the input and the visibility trigger.

Invalid

Set invalid to give the input the error border. Add the error text below it, here with the field recipe's errorText. readOnly and required go on the root the same way.

Use at least 8 characters.

Translations

The visibility trigger's label is "Show password" or "Hide password". Pass translations.visibilityTrigger to change it; it gets whether the password is visible.

Recipe

VariantValuesDefault
variantoutline, subtle, flushedoutline
sizexs, sm, md, lgmd
VariableDescription
--input-heightThe input height, set by size. The visibility trigger is a square of it
--focus-colorThe focus ring color, colors.colorPalette.focusRing
--error-colorThe border and focus ring color when invalid, colors.border.error