# Password input (UI SDK): Controlled visibility

> Pass `visible` and `onVisibleChange`. The reason tells a toggle press from a form submit, a reset or the page being hidden.

Canonical: https://hextaui.com/docs/ui-sdk-password-input/examples/controlled

Component docs: https://hextaui.com/docs/ui-sdk-password-input

## Add this example

```bash
npx shadcn@latest add https://hextaui.com/r/ui-sdk-password-input-controlled.json
```

This adds `components/examples/ui-sdk-password-input/controlled.tsx` with the Password input component and the HextaUI theme tokens.

## Source

```tsx title="components/examples/ui-sdk-password-input/controlled.tsx"
"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import {
  PasswordInput,
  PasswordInputControl,
  PasswordInputGroup,
  PasswordInputToggle,
} from "@/components/ui/ui-sdk-password-input"

function UiSdkPasswordInputControlled() {
  const [visible, setVisible] = React.useState(false)
  const [reason, setReason] = React.useState<string | null>(null)

  return (
    <div className="flex w-full max-w-64 flex-col gap-2">
      <Label htmlFor="controlled-password">Password</Label>
      <PasswordInput
        visible={visible}
        onVisibleChange={(next, details) => {
          setVisible(next)
          setReason(details.reason)
        }}
      >
        <PasswordInputGroup>
          <PasswordInputControl id="controlled-password" />
          <PasswordInputToggle />
        </PasswordInputGroup>
      </PasswordInput>
      <p className="m-0 text-xs text-muted-foreground">
        {reason
          ? `${visible ? "Shown" : "Hidden"} by ${reason}.`
          : "Hidden. Press the eye to show it."}
      </p>
    </div>
  )
}

export { UiSdkPasswordInputControlled }
```

## Props in this example

### PasswordInput

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `visible` | `boolean` | – |  |
| `onVisibleChange` | `(visible: boolean, details) => void` | – | details.reason is toggle-press, form-submit, reset, page-hide or imperative. |

### PasswordInputControl

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `id` | `string` | – |  |

## More Password input examples

- [New password](https://hextaui.com/docs/ui-sdk-password-input/examples/new-password)
- [Sign in](https://hextaui.com/docs/ui-sdk-password-input/examples/sign-in)
- [Shown at first](https://hextaui.com/docs/ui-sdk-password-input/examples/visible)
- [Suggest a password](https://hextaui.com/docs/ui-sdk-password-input/examples/controller)
- [Invalid](https://hextaui.com/docs/ui-sdk-password-input/examples/invalid)
- [Read-only](https://hextaui.com/docs/ui-sdk-password-input/examples/read-only)
- [Disabled](https://hextaui.com/docs/ui-sdk-password-input/examples/disabled)
- [Right to left](https://hextaui.com/docs/ui-sdk-password-input/examples/rtl)
