Password Input

A styled and accessible password input component that captures sensitive user credentials with masked text display.

import {PasswordInput} from "@qualcomm-ui/react/password-input"

Examples

Simple

The simple API bundles all subcomponents together into a single component.

Optional hint
<PasswordInput
  className="w-72"
  clearable
  hint="Optional hint"
  label="Password"
  placeholder="Create password"
/>

Icons (Simple)

Add a startIcon to the simple <PasswordInput> using the prop at the root. Unlike the <TextInput>, the endIcon is not supported because its slot is reserved for the password visibility trigger.

Composite

The composite pattern provides full control over the component's elements by composing individual subcomponents.

Optional hint
<PasswordInput.Root className="w-72">
  <PasswordInput.Label>Password</PasswordInput.Label>
  <PasswordInput.InputGroup>
    <PasswordInput.Input placeholder="Placeholder text" />
    <PasswordInput.VisibilityTrigger />
  </PasswordInput.InputGroup>
  <PasswordInput.Hint>Optional hint</PasswordInput.Hint>
</PasswordInput.Root>

Controlled Value

Set the initial value using the defaultValue prop, or use value and onValueChange to control the value manually. These props follow our controlled state pattern.

import {type ReactElement, useState} from "react"

import {Button} from "@qualcomm-ui/react/button"
import {PasswordInput} from "@qualcomm-ui/react/password-input"

export default function PasswordInputControlledValueDemo(): ReactElement {
  const [value, setValue] = useState<string>("passw0rd")

  return (
    <div className="flex items-end gap-4">
      <PasswordInput
        className="w-72"
        label="Password"
        onValueChange={(updatedValue) => {
          console.debug("Value changed:", updatedValue)
          setValue(updatedValue)
        }}
        placeholder="Enter your password"
        value={value}
      />

      <Button emphasis="primary" onClick={() => setValue("")} variant="outline">
        Reset
      </Button>
    </div>
  )
}

Controlled Visibility

Set the initial visibility using the defaultVisible prop, or use visible and onVisibleChange to control the visibility manually. These props follow our controlled state pattern.

import {type ReactElement, useState} from "react"

import {Button} from "@qualcomm-ui/react/button"
import {PasswordInput} from "@qualcomm-ui/react/password-input"

export default function PasswordInputControlledVisibilityDemo(): ReactElement {
  const [visible, setVisible] = useState<boolean>(false)

  return (
    <div className="flex flex-col gap-4">
      <PasswordInput
        className="w-72"
        defaultValue="passw0rd"
        label="Password"
        onVisibleChange={setVisible}
        placeholder="Enter your password"
        visible={visible}
      />

      <Button
        emphasis="primary"
        onClick={() => setVisible(!visible)}
        variant="outline"
      >
        {visible ? "Hide Password" : "Show Password"}
      </Button>
    </div>
  )
}

Forms

React Hook Form

must be 8+ characters with at least 1 number, lowercase, uppercase, and special character.

TanStack Form

must be 8+ characters with at least 1 number, lowercase, uppercase, and special character.

API

<PasswordInput>

The PasswordInput extends the PasswordInput.Root with the following props:

PropTypeDefault
When true, renders a clear button that resets the input value on click. The button only appears when the input has a value.
boolean
false
Props applied to the error indicator element.
Optional error that describes the element when invalid is true.
string
Props applied to the error text element.
Optional hint describing the element. This element is automatically associated with the component's input element for accessibility.
Props applied to the label element.
Props applied to the input group element.
Props applied to the input element.
Optional label describing the element. Recommended. This element is automatically associated with the component's input element for accessibility.
Props applied to the label element.
HTML placeholder attribute, passed to the underlying input element.
string
Props applied to the visibility trigger element.
Type
boolean
Description
When true, renders a clear button that resets the input value on click. The button only appears when the input has a value.
Description
Props applied to the error indicator element.
Type
string
Description
Optional error that describes the element when invalid is true.
Description
Props applied to the error text element.
Description
Optional hint describing the element. This element is automatically associated with the component's input element for accessibility.
Description
Props applied to the label element.
Description
Props applied to the input group element.
Description
Props applied to the input element.
Description
Optional label describing the element. Recommended. This element is automatically associated with the component's input element for accessibility.
Description
Props applied to the label element.
Type
string
Description
HTML placeholder attribute, passed to the underlying input element.
Description
Props applied to the visibility trigger element.

Composite API

<PasswordInput.Root>

PropTypeDefault
The autocomplete attribute for the password input.
| 'current-password'
| 'new-password'
"current-password"
React children prop.
The initial value of the input when rendered. Use when you don't need to control the value of the input.
string
The default visibility of the password input.
boolean
The document's text/writing direction.
'ltr' | 'rtl'
'ltr'
Whether the input is disabled. When true, prevents user interaction and applies visual styling to indicate the disabled state.
boolean
The id of the form that the input belongs to.
string
A root node to correctly resolve document in custom environments. i.e., Iframes, Electron.
    () =>
    | Node
    | ShadowRoot
    | Document
    The ids of the elements that are associated with the input. These will be automatically generated if omitted.
    Partial<{
    errorText: string
    hint: string
    input: string
    label: string
    visibilityTrigger: string
    }>
    Controls the visual error state of the input. When true, applies semantic error styling to indicate validation failure.
    boolean
    The name of the input field. Useful for form submission.
    string
    The callback invoked when the field is focused or blurred.
      (
      focused: boolean,
      ) => void
      The callback invoked when the value changes.
        (
        value: string,
        ) => void
        Function called when the visibility changes.
          (
          visible: boolean,
          ) => void
          Whether the input is read-only. When true, prevents user interaction while keeping the input focusable and visible.
          boolean
          Allows you to replace the component's HTML element with a different tag or component. Learn more
          | ReactElement
          | ((
          props: object,
          ) => ReactElement)
          Whether the input is required. When true, the input must have a value for form validation to pass.
          boolean
          The size of the input field and its elements. Governs properties like font size, item padding, and icon sizes.
          | 'sm'
          | 'md'
          | 'lg'
          'md'
          
          lucide icon, positioned at the start of the input field.
          | LucideIcon
          | ReactNode
          Localized messages to use for element labels.
          {
          visibilityTrigger?: (
          visible: boolean,
          ) => string
          }
          The controlled value of the input
          string
          Whether the password input is visible.
          boolean
          Type
          | 'current-password'
          | 'new-password'
          Description
          The autocomplete attribute for the password input.
          Description
          React children prop.
          Type
          string
          Description
          The initial value of the input when rendered. Use when you don't need to control the value of the input.
          Type
          boolean
          Description
          The default visibility of the password input.
          Type
          'ltr' | 'rtl'
          Description
          The document's text/writing direction.
          Type
          boolean
          Description
          Whether the input is disabled. When true, prevents user interaction and applies visual styling to indicate the disabled state.
          Type
          string
          Description
          The id of the form that the input belongs to.
          Type
          () =>
          | Node
          | ShadowRoot
          | Document
          Description
          A root node to correctly resolve document in custom environments. i.e., Iframes, Electron.
            Type
            Partial<{
            errorText: string
            hint: string
            input: string
            label: string
            visibilityTrigger: string
            }>
            Description
            The ids of the elements that are associated with the input. These will be automatically generated if omitted.
            Type
            boolean
            Description
            Controls the visual error state of the input. When true, applies semantic error styling to indicate validation failure.
            Type
            string
            Description
            The name of the input field. Useful for form submission.
            Type
            (
            focused: boolean,
            ) => void
            Description
            The callback invoked when the field is focused or blurred.
              Type
              (
              value: string,
              ) => void
              Description
              The callback invoked when the value changes.
                Type
                (
                visible: boolean,
                ) => void
                Description
                Function called when the visibility changes.
                  Type
                  boolean
                  Description
                  Whether the input is read-only. When true, prevents user interaction while keeping the input focusable and visible.
                  Type
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                  Type
                  boolean
                  Description
                  Whether the input is required. When true, the input must have a value for form validation to pass.
                  Type
                  | 'sm'
                  | 'md'
                  | 'lg'
                  Description
                  The size of the input field and its elements. Governs properties like font size, item padding, and icon sizes.
                  Type
                  | LucideIcon
                  | ReactNode
                  Description
                  lucide icon, positioned at the start of the input field.
                  Type
                  {
                  visibilityTrigger?: (
                  visible: boolean,
                  ) => string
                  }
                  Description
                  Localized messages to use for element labels.
                  Type
                  string
                  Description
                  The controlled value of the input
                  Type
                  boolean
                  Description
                  Whether the password input is visible.

                  <PasswordInput.InputGroup>

                  PropType
                  React children prop.
                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  React children prop.
                  Type
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                  <PasswordInput.Label>

                  PropType
                  React children prop.
                  Whether the input is required. When true, the field will show a required indicator.
                  boolean
                  Description
                  React children prop.
                  Type
                  boolean
                  Description
                  Whether the input is required. When true, the field will show a required indicator.

                  <PasswordInput.Hint>

                  PropType
                  React children prop.
                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  React children prop.
                  Type
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                  <PasswordInput.ClearTrigger>

                  PropType
                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Type
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                  <PasswordInput.Input>

                  <PasswordInput.ErrorText>

                  PropType
                  An icon to display next to the error text.
                  | LucideIcon
                  | ReactNode
                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Type
                  | LucideIcon
                  | ReactNode
                  Description
                  An icon to display next to the error text.
                  Type
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                  <PasswordInput.ErrorIndicator>

                  PropTypeDefault
                  lucide-react icon or ReactNode.
                  | LucideIcon
                  | ReactNode
                  CircleAlert
                  
                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Type
                  | LucideIcon
                  | ReactNode
                  Description
                  lucide-react icon or ReactNode.
                  Type
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  Allows you to replace the component's HTML element with a different tag or component. Learn more

                  <PasswordInput.VisibilityTrigger>

                  PropTypeDefault
                  React children prop.
                  The icon shown when the input text is visible.
                  | LucideIcon
                  | ReactNode
                  EyeOff
                  
                  The icon shown when the input text is hidden.
                  | LucideIcon
                  | ReactNode
                  Eye
                  
                  Allows you to replace the component's HTML element with a different tag or component. Learn more
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  React children prop.
                  Type
                  | LucideIcon
                  | ReactNode
                  Description
                  The icon shown when the input text is visible.
                  Type
                  | LucideIcon
                  | ReactNode
                  Description
                  The icon shown when the input text is hidden.
                  Type
                  | ReactElement
                  | ((
                  props: object,
                  ) => ReactElement)
                  Description
                  Allows you to replace the component's HTML element with a different tag or component. Learn more