Skip to content
EspañolEnglish
All components (283)

Input group

Fields · InputGroup

What it is and when to use it

A field with segments stuck to it: https:// + the domain + .com, an amount with its currency in front, a code with its copy button behind. It is a single box -one border, one focus ring, one error- with the field in the middle and each segment with its own background, separated by a rule.

When to use it

  • When what surrounds the field is part of what is typed but not of the value: a prefix, a unit, an action that operates on it.
  • For a button that acts on the field (copy, paste, generate) and must look like part of it.

When not to

  • For an ornament inside the field (a magnifier, a small unit): that is front or back of TextField.
  • For two independent controls that touch: that is CompactGroup.
  • For a chat box: that is PromptInput.

Keyboard: it is a single field; Tab goes from the segment with a button to the field and back, in the order they are seen. Pressing the label focuses the field.

Accessibility: it carries everything TextField does: the label is required, the hint and the error are linked with aria-describedby and the error marks the field as invalid. value is only what is typed: the segments are not mixed into it. A text segment is content of the box and is read with it; if what is inside is a button, it needs its own name.

Fine-tuning: CSS variable --amset-inputgroup-addon-background (the background of the segments), besides the --amset-field-* of the box.

What it looks like

https://.tienda.example
Lowercase letters, numbers and hyphens only.
€VAT incl.

<InputGroup
  label="Your shop address"
  start="https://"
  end=".tienda.example"
  placeholder="aurelia-jewellery"
  hint="Lowercase letters, numbers and hyphens only."
/>
<InputGroup label="Price" start="€" end="VAT incl." placeholder="0,00" numeric />

Props

Import it with import { InputGroup } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
labelrequiredstringRequired: a field without a visible label does not get into the library.
bottomReactNodeA strip BELOW the field, inside the box: a count, a keyboard shortcut, a send button.
classNamestring—
clearablebooleanA button to empty the field, shown as soon as something is typed. Pressing it puts the focus back in the input.
clearLabelstringWhat the screen reader says on the clear button. By default, “Clear text”.
countByCountStrategyHow characters are counted: `graphemes` (default, an emoji is one), `characters` or a custom function.
counterbooleanShows "12 / 40" under the field, with the limit of `maxCount` or `maxLength`.
defaultValuestring—
disabledboolean—
endReactNodeA segment AFTER the field: ".com", "kg", a copy button.
errorstringError message. When it is passed, the field is marked as invalid.
errorMessage(details: NativeValidation) => string | null | undefinedThe message when the typed text does not meet the field's NATIVE rules (`minLength`, `maxLength`, `pattern`, `type` `email` or `url`): it receives the text and its `validity` (`tooShort`, `patternMismatch`, `typeMismatch`...) and returns the message, in your language and your words, instead of the browser's bubble. It is checked like `validate`: on leaving and, once it has failed, on every key. `validate` and `error` take precedence over this.
hiddenLabelbooleanThe label for the screen reader only. For when the field sits inside something that already explains itself (a table cell, a group of filters), never to save space.
hintstringPermanent hint text below the field. It does not replace the label.
inputRefRef<HTMLInputElement>The real `<input>`, to focus it, select its text or measure it from outside. It is separate from `ref` because the component paints a box with label, hint and error, and whoever asks for a ref almost always wants the control.
invalidboolean—
loadingbooleanSomething about this field is being checked or loaded (whether the name is free, the address): a ring inside the box and `aria-busy` on the field. Typing can go on.
loadingPosition"start" | "end"Where the ring goes: `end` (default) or `start`, in the place of the leading icon.
maxCountnumberA limit that WARNS without cutting: typing can go on, the count turns red, the field is marked invalid and how many are left over is announced. To cut off hard there is `maxLength`. With `maxCount` the counter shows even if not asked for.
numericbooleanFixed-width digits (amounts, tax IDs, dates).
onChange(value: string) => void—
onChangeEvent(event: ChangeEvent<HTMLInputElement>) => voidLike `onChange`, but with the native event of the `<input>`: `e.target.value`, `e.currentTarget`... It exists to migrate a front end that already writes its handlers with the event (AMS-735). If you only want the text, `onChange` already gives it to you.
onClear() => voidCalled when the field is emptied with the button, after `onChange('')`.
placeholderstring—
readOnlyboolean—
requiredboolean—
size"sm" | "md" | "lg"—
startReactNodeA segment BEFORE the field, with its own background and divider: "https://", a currency, a selector. It is part of the box and its focus ring, but not of the text: `value` is only what is typed.
successstringThe confirmation that what was typed is valid ("Username available"). An error or a warning take precedence over it.
topReactNodeA strip ABOVE the field, inside the same box and across its whole width: a file name, a status tag, some formatting buttons. The field and its segments stay below, in the same row.
validate(value: string) => string | null | undefinedChecks what was typed and returns the error message, or nothing if it is valid. It runs when leaving the field and, once it has failed, on every keystroke, so the error goes away as soon as it is fixed. An external `error` takes precedence.
validationBehavior"aria" | "native"`aria` (the default) announces the state without the browser interrupting submission with its bubble; `native` also adds its own validation.
valuestring—
variantFieldVariant—
warningstringA warning that lets you go on, with its icon and colour, where the error would go. The field is still valid.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: