Skip to content
BigBang

Popular

    ↑↓Navigate↵OpenEscClose
    TR

    Components

    PasswordInput

    A password field with an eye button, and an optional rule list, strength bar and Caps Lock warning.

    Storybook
    Storybook
    Source
    Source

    The example below loads live from Storybook; open it there to use the controls.

    Live example, StorybookOpen in Storybook

    The eye button shows and hides the value; its pressed state is reported with aria-pressed.

    import { PasswordInput, Provider } from '@bigbang/ui';
    export default function Default() {
    return (
    <Provider locale="en-GB">
    <PasswordInput label="Password" autoComplete="current-password" className="max-w-sm" />
    </Provider>
    );
    }

    With a description, invalid and disabled.

    Help text goes here.

    The password does not meet the requirements.
    import { PasswordInput, Provider } from '@bigbang/ui';
    export default function States() {
    return (
    <Provider locale="en-GB">
    <div className="flex max-w-sm flex-col gap-lg">
    <PasswordInput label="Password" autoComplete="current-password" description="Help text goes here." />
    <PasswordInput label="Password" autoComplete="current-password" defaultValue="short" error="The password does not meet the requirements." />
    <PasswordInput label="Password" autoComplete="current-password" defaultValue="sample-value-1" disabled />
    </div>
    </Provider>
    );
    }

    rules shows a checklist under the field and links it to the field; a met rule turns green. showStrength adds a three-step strength bar.

    • At least 12 characters, not met
    • One capital letter, met
    • One digit, met
    Password strength: fair
    import { PasswordInput, Provider } from '@bigbang/ui';
    const rules = [
    { id: 'length', label: 'At least 12 characters', test: (value: string) => value.length >= 12 },
    { id: 'upper', label: 'One capital letter', test: (value: string) => /[A-Z]/.test(value) },
    { id: 'digit', label: 'One digit', test: (value: string) => /\d/.test(value) },
    ];
    export default function NewPassword() {
    return (
    <Provider locale="en-GB">
    <PasswordInput className="max-w-sm" label="New password" autoComplete="new-password" rules={rules} showStrength defaultValue="Sample1" required />
    </Provider>
    );
    }

    Rule and strength colours are semantic status tokens.

    • At least 12 characters, not met
    • One capital letter, met
    • One digit, met
    Password strength: fair
    • At least 12 characters, not met
    • One capital letter, met
    • One digit, met
    Password strength: fair
    import { PasswordInput, Provider } from '@bigbang/ui';
    const rules = [
    { id: 'length', label: 'At least 12 characters', test: (value: string) => value.length >= 12 },
    { id: 'upper', label: 'One capital letter', test: (value: string) => /[A-Z]/.test(value) },
    { id: 'digit', label: 'One digit', test: (value: string) => /\d/.test(value) },
    ];
    export default function NewPassword() {
    return (
    <Provider locale="en-GB">
    <PasswordInput className="max-w-sm" label="New password" autoComplete="new-password" rules={rules} showStrength defaultValue="Sample1" required />
    </Provider>
    );
    }