Skip to main content
On this page

Subcomponents

Subcomponents are low-level primitives for building custom form fields and inputs with consistent Nebula styling.

When to use​

  • When building a custom form field that has no Nebula field equivalent
  • When you need direct access to an input element for integration with a third-party form library that requires a ref
  • When a higher-level Nebula field component (such as TextField or SelectField) does not support the specific layout or behaviour your context requires

When not to use​

  • When a full field component exists - if TextField, SelectField, TextareaField, CheckboxField, RadioField, DateField, DatepickerField, CurrencyField, or ComboboxField fits your use case, use it. The field components handle label association, hint text, error text, required/optional marking, and aria attributes automatically.
  • To assemble a field without using Field - if you are composing an input with a label, use the Field wrapper rather than assembling label and error elements manually. Manual assembly is likely to miss aria associations.

Anatomy​

  1. Field wrapper (handles label, optional/required marking, hint, error text, and aria attribute injection)
  2. Input (the focusable form control rendered inside the field wrapper)

Basic usage​

Use Field to wrap any *Input component. Field injects id, name, aria-invalid, aria-required, and aria-describedby onto its direct child automatically.

Loading...
Edit live code
<Field
    id="name"
    label="Name"
    hint="Used for contacting you"
    error="Enter a name"
    characters={10}
>
  <TextInput />
</Field>

Variants and features​

Field​

Field is a layout and accessibility wrapper for form inputs. It renders a label, optional hint text, and error text, and injects the appropriate aria attributes onto its child input.

Props:

  • label: the visible label text (required)
  • id: used to associate the label with the input (required)
  • hint: descriptive text shown below the label
  • error: validation message shown below the input; overrides any error supplied by a parent Form
  • optional: when true, appends "(optional)" to the label (or suppresses the required asterisk, depending on theme configuration)
  • fullWidth: controls how the input width responds to the viewport: 'small' (full width on small screens, character-width on larger), 'always', or 'never'
  • characters: approximate visible character count used to calculate the input width on larger viewports (default: 25)
Loading...
Edit live code
<Stack spaceBetween={4}>
  <Field id="field-hint" label="Account name" hint="As it appears on your bill">
    <TextInput />
  </Field>
  <Field id="field-error" label="Account number" error="Enter an account number">
    <NumberInput />
  </Field>
  <Field id="field-optional" label="Reference" optional characters={12}>
    <TextInput />
  </Field>
</Stack>

TextInput​

A standard single-line text input. Accepts iconLeft and iconRight props to place icons inside the input.

Loading...
Edit live code
<Field id="search" label="Search">
  <TextInput iconLeft="search" />
</Field>

NumberInput​

A text input configured for numeric entry. Sets inputMode="numeric", pattern="[0-9]*", and disables autocapitalise, autocorrect, and spellcheck. Use for whole numbers. For decimal amounts, use CurrencyInput or set inputMode="decimal" via props.

Loading...
Edit live code
<Field id="meter-read" label="Meter reading">
  <NumberInput />
</Field>

TextareaInput​

A multi-line text input. Defaults to 3 rows with vertical resizing disabled. Pass resizable to allow the user to resize.

Loading...
Edit live code
<Field id="notes" label="Notes">
  <TextareaInput rows={5} resizable />
</Field>

SelectInput​

A styled native <select> element with a custom chevron icon. Accepts an options array of { value, label } objects, or standard <option> children.

Loading...
Edit live code
<Field id="tariff" label="Tariff">
  <SelectInput options={[{ value: 'fixed', label: 'Fixed' }, { value: 'variable', label: 'Variable' }]} />
</Field>

CurrencyInput​

A number input with a currency icon on the left and a visually hidden currency label for screen readers. Defaults to GBP. Accepts currency as 'GBP', 'EUR', 'AUD', or 'USD'.

For most currency entry, prefer the CurrencyField component, which wraps Field and CurrencyInput together.

Loading...
Edit live code
<Field id="amount" label="Amount">
  <CurrencyInput currency="GBP" />
</Field>

EmailInput, TelInput, PasswordInput​

Variants of the base input pre-configured for their respective input types:

  • EmailInput: sets type="email" and disables autocapitalise/autocorrect
  • TelInput: sets type="tel"
  • PasswordInput: sets type="password" and disables autocapitalise, autocorrect, and spellcheck
Loading...
Edit live code
<Stack spaceBetween={4}>
  <Field id="sub-email" label="Email address">
    <EmailInput />
  </Field>
  <Field id="sub-tel" label="Mobile number">
    <TelInput />
  </Field>
  <Field id="sub-password" label="Password" hint="At least 12 characters">
    <PasswordInput />
  </Field>
</Stack>