Skip to content
BigBang

Popular

    ↑↓Navigate↵OpenEscClose
    TR

    Components

    Field

    The wrapper that wires label, control, help text, error and counter by ids for any form control.

    Storybook
    Storybook
    Source
    Source

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

    Live example, StorybookOpen in Storybook

    Field binds the label to the control with <label> and the help text with aria-describedby. A bare Field.Control renders an <input> with the TextInput look.

    Help text goes here.

    import { Field } from '@bigbang/ui';
    export default function Default() {
    return (
    <div className="max-w-80">
    <Field label="Field label" description="Help text goes here.">
    <Field.Control />
    </Field>
    </div>
    );
    }

    required adds * and a visually hidden “required” to the label. necessityIndicator="optional" writes “(optional)” on the fields that are not required.

    import { Field, Provider } from '@bigbang/ui';
    export default function Necessity() {
    return (
    <Provider locale="en-GB">
    <div className="flex max-w-80 flex-col gap-lg">
    <Field label="Field label" required>
    <Field.Control required />
    </Field>
    <Field label="Field label" necessityIndicator="optional">
    <Field.Control />
    </Field>
    </div>
    </Provider>
    );
    }

    error makes the field invalid. Pass a list for several messages; they render as a bulleted list and are linked to the control.

    This field cannot be empty.

    Help text goes here.

    • This field cannot be empty.
    • Enter at least 3 characters.
    import { Field } from '@bigbang/ui';
    export default function Errors() {
    return (
    <div className="flex max-w-80 flex-col gap-lg">
    <Field label="Field label" error="This field cannot be empty.">
    <Field.Control />
    </Field>
    <Field label="Field label" description="Help text goes here." error={['This field cannot be empty.', 'Enter at least 3 characters.']}>
    <Field.Control />
    </Field>
    </div>
    );
    }

    Field.Counter shows the characters used against the limit. From 80 % of the limit the remaining characters are announced politely; over the limit the counter turns danger.

    Help text goes here.

    import { Field, Provider } from '@bigbang/ui';
    import { useState } from 'react';
    export default function Counter() {
    const [value, setValue] = useState('');
    return (
    <Provider locale="en-GB">
    <div className="max-w-80">
    <Field label="Field label" description="Help text goes here.">
    <Field.Control value={value} onValueChange={setValue} />
    <Field.Counter value={value} max={20} />
    </Field>
    </div>
    </Provider>
    );
    }

    Colours come from the color-text-* and color-border-* tokens.

    This field cannot be empty.

    Help text goes here.

    • This field cannot be empty.
    • Enter at least 3 characters.
    This field cannot be empty.

    Help text goes here.

    • This field cannot be empty.
    • Enter at least 3 characters.
    import { Field } from '@bigbang/ui';
    export default function Errors() {
    return (
    <div className="flex max-w-80 flex-col gap-lg">
    <Field label="Field label" error="This field cannot be empty.">
    <Field.Control />
    </Field>
    <Field label="Field label" description="Help text goes here." error={['This field cannot be empty.', 'Enter at least 3 characters.']}>
    <Field.Control />
    </Field>
    </div>
    );
    }