Password Input
View as MarkdownA password field with a button that shows and hides what you typed.
Features
Permalink to heading "Features"- Toggles the password between hidden and plain text
- Keeps focus in the input when the visibility trigger is clicked, and leaves the trigger out of the tab order
- Hides the password again when its form is submitted or reset
- Sets
autocompletetocurrent-passwordornew-passwordfor browser autofill - Keeps password managers away with
ignorePasswordManagers - Works with Field: takes its name, required, disabled, readonly and invalid state from it
<primitives:passwordInput.root>
<primitives:passwordInput.label />
<primitives:passwordInput.control>
<primitives:passwordInput.input />
<primitives:passwordInput.visibilityTrigger>
<primitives:passwordInput.indicator />
</primitives:passwordInput.visibilityTrigger>
</primitives:passwordInput.control>
</primitives:passwordInput.root>
Installation
Permalink to heading "Installation"typo3 ui:add passwordInput
Please copy the files manually from GitHub into your project: PasswordInput
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Use it in a sign-up form
Permalink to heading "Use it in a sign-up form"Nest ui:passwordInput.root in ui:field.root. The password input takes name, required, disabled, invalid and aria-describedby from the field. Set autoComplete to new-password, so the browser offers to generate a strong password. Type fewer than 12 characters in the demo and leave the input to see the error.
Keep password managers away
Permalink to heading "Keep password managers away"Set ignorePasswordManagers="{true}" for a password that is not the visitor's own login, like the guest Wi-Fi password in the demo. 1Password, LastPass, Bitwarden, Dashlane and Proton Pass then leave the input alone. defaultVisible="{true}" shows the password when the page loads.
Swap the icons
Permalink to heading "Swap the icons"Put one passwordInput.indicator per state into the visibility trigger. The one matching the current state is shown.
<primitives:passwordInput.visibilityTrigger>
<primitives:passwordInput.indicator
state="{f:constant(name: 'Jramke\FluidPrimitives\Enum\PasswordInputIndicatorState::Hidden')}"
>Show</primitives:passwordInput.indicator
>
<primitives:passwordInput.indicator
state="{f:constant(name: 'Jramke\FluidPrimitives\Enum\PasswordInputIndicatorState::Visible')}"
>Hide</primitives:passwordInput.indicator
>
</primitives:passwordInput.visibilityTrigger>
Localization
Permalink to heading "Localization"The labels of the visibility trigger ship in the language file and follow the site language. Pass translations to override them for one password input: visibilityTriggerLabelHidden is read while the password is hidden ("Show password"), visibilityTriggerLabelVisible while it is shown.
<f:variable
name="passwordTranslations"
value="{
visibilityTriggerLabelHidden: '{f:translate(key: \'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:forms.pin.show\')}',
visibilityTriggerLabelVisible: '{f:translate(key: \'LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:forms.pin.hide\')}'
}"
/>
<ui:passwordInput.root translations="{passwordTranslations}"> ... </ui:passwordInput.root>
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.
passwordInput.root
Permalink to heading "passwordInput.root"Provides shared password input state and wraps all related parts. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
disabled | booleanWhether the password input is disabled. Inherited from a surrounding field when available. | No | - |
invalid | booleanWhether the password input value is invalid. Inherited from a surrounding field when available. | No | - |
required | booleanWhether the password input is required. Inherited from a surrounding field when available. | No | - |
readOnly | booleanWhether the password input is readonly. Inherited from a surrounding field when available. | No | - |
name | stringThe name attribute of the password input. Useful for form submission. Inherited from a surrounding field when available. | No | - |
defaultVisible | booleanWhether the password is shown as plain text when rendered. | No | false |
autoComplete | Enum\PasswordAutoCompleteThe autocomplete attribute of the input. Use `new-password` on a sign-up or change-password form, so the browser offers to generate a password. | No | CurrentPassword |
ignorePasswordManagers | booleanWhether password managers leave the input alone. Works for 1Password, LastPass, Bitwarden, Dashlane and Proton Pass. | No | false |
translations | arrayLocalized labels of the visibility trigger, `visibilityTriggerLabelHidden` and `visibilityTriggerLabelVisible`. A client script can pass a `visibilityTrigger` function of the visible state instead. Use `f:translate` for per-template localization overrides when needed. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
provider | stringThe `id` of the `.provider` this root takes its `rootId` and props from. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-password-input-root | <uid> |
data-disabled | Present when disabled |
data-invalid | Present when invalid |
data-readonly | Present when read-only |
passwordInput.label
Permalink to heading "passwordInput.label"Labels the password input. Renders a <label> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| 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 |
passwordInput.control
Permalink to heading "passwordInput.control"Groups the input and the visibility trigger. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-password-input-control | <uid> |
data-disabled | Present when disabled |
data-invalid | Present when invalid |
data-readonly | Present when read-only |
passwordInput.input
Permalink to heading "passwordInput.input"Provides the password input. Renders an <input> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| 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 |
passwordInput.visibilityTrigger
Permalink to heading "passwordInput.visibilityTrigger"Shows or hides the password. Renders a <button> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-password-input-visibility-trigger | <uid> |
data-readonly | Present when read-only |
data-disabled | Present when disabled |
data-state | "visible" | "hidden" |
passwordInput.indicator
Permalink to heading "passwordInput.indicator"Shows content for one visibility state. Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
state | Enum\PasswordInputIndicatorStateThe visibility state the indicator is shown in. | Yes | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| 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 |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
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. |
getInputState | () => InputState | Returns the state of the input. |
getVisibilityTriggerState | () => VisibilityTriggerState | Returns the state of the visibility trigger. |