PasswordInput

Text input for editing password values, with a button to toggle visibility.

Installation

pnpm dlx shadcn@latest add @shadmin/password-input

Usage

import { PasswordInput } from "@/components/admin";
 
<PasswordInput source="password" />;

By default the value is hidden as ••••••. Click the eye button to toggle visibility.

Props

PropRequiredTypeDefaultDescription
sourceRequiredstring-Field name
classNameOptionalstring-Wrapper classes
defaultValueOptionalstring-Default value
disabledOptionalboolean-If true, the input is disabled
formatOptionalfunction-Callback taking the value from the form state, and returning the input value
helperTextOptionalReactNode-Help text
initiallyVisibleOptionalbooleanfalseWhether the password should be shown in plain text on first render
inputClassNameOptionalstring-Classes applied to the underlying <input> element
labelOptionalstring | falseInferredCustom / hide label
parseOptional(value:string) => any-Callback taking the value from the input, and returning the value to be stored in the form state
placeholderOptionalstring-Placeholder text
validateOptionalValidator | Validator[]-Validation

Additional props are forwarded to the underlying <TextInput> (and ultimately to the HTML <input>).

initiallyVisible

Set initiallyVisible to true to make the password value visible by default:

<PasswordInput source="password" initiallyVisible />

Validation

Combine PasswordInput with ra-core validators to enforce password rules:

import { minLength, required } from "ra-core";
import { PasswordInput } from "@/components/admin";
 
<PasswordInput source="password" validate={[required(), minLength(8)]} />;