A Material-UI password text field with password strength indicator.
npm install mui-password-strength-input
or
yarn add mui-password-strength-input
Please note that @mui/material (and their @emotion/ peers) are peer dependencies, meaning you should ensure they are installed before installing mui-password-strength-input.
npm install @mui/material @emotion/react @emotion/styledor
yarn add @mui/material @emotion/react @emotion/styledimport PasswordStrengthInput from 'password-strength-input';
function App() {
const [password, setPassword] = useState<string>('');
const handlePasswordChange = (value: string) => setPassword(value);
return (
<PasswordStrengthInput value={value} onChange={handlePasswordChange} />
);
} <PasswordStrengthInput
options={{
tooWeak: {
label: 'Trop faible',
color: 'red',
},
weak: {
label: 'Faible',
color: 'yellow',
},
medium: {
label: 'Moyen',
color: 'green',
},
strong: {
label: 'Fort',
color: 'blue'
},
}}
/> <PasswordStrengthInput
options={{
tooWeak: {
label: 'Trop faible',
color: 'red',
},
weak: {
label: 'Faible',
},
medium: {
color: 'green',
},
}}
/> <PasswordStrengthInput
barClassName="!w-[50px]"
strengthLabelClassName="!text-xl"
className="!w-full
/> <PasswordStrengthInput
hidePasswordIcon={<EyeOff />}
showPasswordIcon={<EyeOn />}
/> <PasswordStrengthInput
placeholder="Enter your password"
// ...other mui TextField props
/>See here for more examples that use PasswordStrengthInput.
| Props | Type | Default value | Description |
|---|---|---|---|
| options | Options |
null | Options to override colors and labels of each strength |
| barClassName | string |
empty | Each bar indicator class name |
| strengthLabelClassName | string |
empty | Strength label class name |
| className | string |
empty | TextField class name |
| hidePasswordIcon | ReactNode |
null | Custom icon to hide password |
| hidePasswordIcon | ReactNode |
null | Custom icon to show password |
| barWidth | number |
null | Width of each bar. By default, if not defined the bar will use flex 1 |
| ...otherProps | TextFieldProps |
null | All mui TextField props |
Get started here.
