import { PasswordInputDemos } from '@docs/demos';
import { Layout } from '@/layout';
import { MDX_DATA } from '@/mdx';
export default Layout(MDX_DATA.PasswordInput);
## Usage
## Loading state
Set `loading` prop to display a loading indicator. By default, the loader is displayed on the right side of the input.
You can change the position with the `loadingPosition` prop to `'left'` or `'right'`. This is useful for async operations like API calls, searches, or validations:
## Controlled
```tsx
import { useState } from 'react';
import { PasswordInput } from '@mantine/core';
function Demo() {
const [value, setValue] = useState('');
return (
setValue(event.currentTarget.value)}
/>
);
}
```
## Uncontrolled
`PasswordInput` can be used with uncontrolled forms the same way as a native `input[type="password"]`.
Set the `name` attribute to include password input value in `FormData` object on form submission.
To control the initial value in uncontrolled forms, use the `defaultValue` prop.
Example usage of uncontrolled `PasswordInput` with `FormData`:
```tsx
import { PasswordInput } from '@mantine/core';
function Demo() {
return (
);
}
```
## Controlled visibility toggle
Control the visibility state with the `visible` and `onVisibilityChange` props.
For example, the props can be used to sync visibility state between two inputs:
## Change visibility toggle icon
To change the visibility toggle icon, pass a React component that accepts the `reveal` prop to `visibilityToggleIcon`:
## Strength meter example
Password strength meter example with the [Progress](/core/progress/) and [Popover](/core/popover/) components:
## Usage without visibility toggle
If you do not need the visibility toggle button, use the [TextInput](/core/text-input/) component instead:
```tsx
import { TextInput } from '@mantine/core';
function Demo() {
return ;
}
```
Note that when the `rightSection` prop is used, the visibility toggle button is not rendered.
## Error state
## Success state
## Disabled
When the `disabled` prop is set, the visibility toggle button is hidden:
To set `aria-label` on the visibility toggle button, use the `visibilityToggleButtonProps` prop:
```tsx
import { PasswordInput } from '@mantine/core';
function Demo() {
return (
);
}
```
### Visibility toggle focus
By default, the visibility toggle button is excluded from the tab order (`tabindex="-1"`).
This mimics the native browser password reveal control and keeps the form flow uninterrupted:
pressing Tab moves focus to the next field rather than to the toggle button.
The toggle remains operable with a mouse, touch and assistive technologies that navigate by element rather than by tab order.
If your users expect to reach the toggle with Tab, set the `visibilityToggleFocusable` prop.
The button then receives `tabindex="0"` and can be activated with Enter or Space:
To apply this behavior to every `PasswordInput` in your application, set the prop in the [theme](/theming/theme-object/):
```tsx
import { createTheme, PasswordInput } from '@mantine/core';
const theme = createTheme({
components: {
PasswordInput: PasswordInput.extend({
defaultProps: {
visibilityToggleFocusable: true,
},
}),
},
});
```