InputChips

InputChips enters several free-text values, such as tags, keywords or email addresses, each shown as a removable chip. Values are added with Enter, a separator or a paste, checked against limits and your own rules, and the component works with every kind of Angular form.

import { InputChips } from '@exhaustive-ui/core/inputchips';

InputChips is bound with ngModel and its value is an array of strings. Type a value and press Enter to add it as a chip; the text is trimmed and a value that is already in the list is not added twice. Click the icon of a chip, or press Backspace in the empty input and then Backspace again, to remove it.

  • angular
  • signals
Press Delete or Backspace to remove

A separator, a string or a regular expression, splits the text into several chips as it is typed or pasted. Pasting several lines always adds one chip per line. Try pasting red, green, blue below.

With addOnBlur, the text left in the input becomes a chip when the component loses the focus. With addOnTab, the Tab key adds it before moving the focus to the next field.

max limits the number of chips and maxChipLength the length of each chip; values beyond the limits are not added and screen readers hear why. Set allowDuplicate to accept the same value more than once.

  • design
Press Delete or Backspace to remove
  • yes
  • yes
  • no
Press Delete or Backspace to remove

transform turns each value into the text of its chip, here in lowercase, and validate decides whether it can be added. A rejected value stays in the input so that it can be corrected, and onReject tells why.

Press Delete or Backspace to remove

The chip template replaces the content of a chip; its context gives the value, its index, whether it is focused or removable, and a remove function. The removeicon template only replaces the remove icon.

  • TypeScript
  • Rust
Press Delete or Backspace to remove
  • forms
  • accessibility
Press Delete or Backspace to remove

A floating label appears on top of the input field when focused. Visit FloatLabel documentation for more information.

IftaLabel is used to create infield top aligned labels. Visit IftaLabel documentation for more information.

  • Angular
Press Delete or Backspace to remove

InputChips works with IconField and InputIcon to show an icon at the start of the field.

InputChips provides small and large sizes as alternatives to the base.

  • small
Press Delete or Backspace to remove
  • normal
Press Delete or Backspace to remove
  • large
Press Delete or Backspace to remove

Specify the variant property as filled to display the component with a higher visual emphasis than the default outlined style.

The fluid prop makes the component take up the full width of its container when set to true.

When disabled is present, the element cannot be edited and focused. With readonly, the chips can still be focused and read, but not added or removed.

  • disabled
  • readonly

The invalid state is applied using the invalid property to indicate failed validation.

The value is an array of strings, empty when there is no chip, so required works as on the other fields. Enter adds a chip and does not submit the form; on an empty input, it submits the form as usual.

InputChips can also be used with reactive forms. In this case, the formControlName property is used to bind the component to a form control.

InputChips can also be used with Angular Signal Forms. The [formField] directive binds the component to a field holding an array of strings. Signal Forms' required does not treat an empty array as empty, so use minLength(field, 1) to require a chip; maxLength on the field makes more chips invalid without blocking them (use the max input to stop adding), while maxChipLength limits the length of each chip. The field also sets the invalid and touched states of the component, so it is styled as invalid once the field is touched or the form is submitted, like the message below.

Screen Reader

The chips are the options of a horizontal listbox, followed by a text input. Label the component with a label element pointing at inputId, with ariaLabelledBy or with ariaLabel: the input and the list get the same name (the list falls back to the listLabel text). Each chip reports its position in the list, and the list is described by the keys that remove a chip. The remove icon is hidden from screen readers, since the keyboard removes the focused chip. A polite live region announces the chips added and removed, duplicates, rejected values and the max limit.

All these texts can be replaced, or translated, with the labels input.

<label for="tags">Tags</label>
<p-input-chips inputId="tags" />

<span id="recipients">Recipients</span>
<p-input-chips ariaLabelledBy="recipients" />

<p-input-chips ariaLabel="Keywords" [labels]="{ addedMessage: '{0} ajouté', removedMessage: '{0} supprimé' }" />

Input Keyboard Support

KeyFunction
enterAdds the text as a chip. On an empty input, the key is left to the form.
tabMoves the focus to the next field, adding the text first when addOnTab is set.
backspaceOn an empty input, moves the focus to the last chip.
left arrowAt the start of the input, moves the focus to the last chip (right arrow in a right-to-left layout).

Chip Keyboard Support

KeyFunction
left arrowMoves the focus to the previous chip.
right arrowMoves the focus to the next chip, or to the input after the last chip.
home / endMoves the focus to the first or the last chip.
backspaceRemoves the chip and moves the focus to the previous one.
deleteRemoves the chip and moves the focus to the next one.
enter / spaceEmits onChipClick.
escapeMoves the focus back to the input.
any characterMoves the focus to the input, where the character is typed.

The arrows are mirrored in a right-to-left layout. When the last chip is removed, the focus goes back to the input.