Tags Input

A recipe: tags typed into one field, a list of strings for Signal Forms — the Combobox with several values, and an Add item for what is typed. No component of its own.

Usage

Usage

Angular TypeScript

Enter or a comma adds a tag.

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScComboboxChip,  ScComboboxChipRemove,  ScComboboxChips,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxMultiple,  ScComboboxPopup,

How it is made

Base UI's "Creatable" combobox: scCombobox with multiple holds the tags as chips; the list offers the text typed as an item of its own («Add “Docker”»), first, so Enter adds it — and your suggestions after it. Its label is the text, so the chip reads «Docker». A comma adds it too: a beforeinput of yours, picking it as Enter does (pick()).

import { ScComboboxMultiple, ScComboboxChips, ScComboboxChip, ScComboboxChipRemove, ScComboboxInput, ScComboboxPortal, ScComboboxPopup, ScComboboxList, ScComboboxItem } from '@semantic-components/ui';
<div scCombobox multiple autoHighlight [(value)]="tags" #cb="scCombobox">  <div scComboboxChips>    @for (tag of tags(); track tag) {      <span scComboboxChip [value]="tag">        {{ tag }}        <button scComboboxChipRemove>…</button>      </span>    }    <input scComboboxInput (beforeinput)="addOnComma($event, cb)" />  </div>  <ng-template scComboboxPortal>    <div scComboboxPopup>      <div scComboboxList aria-label="…">        @if (typed(cb.query()); as text) {          <div scComboboxItem [value]="text" [label]="text">Add “{{ text }}”</div>        }        @for (tag of matching(cb.query()); track tag) { … }      </div>    </div>  </ng-template></div>

Accessibility

  • The Combobox's: one tab stop; Backspace in an empty input removes the last tag, ← and → reach the chips, and each chip's remove button is named by you («Remove Docker»).
  • The Add item says what it adds, in your words; the chips are the value, read with the field's label.

Examples

Checked before they go in

An address, then Enter or a comma.

import { Component, ViewEncapsulation, signal } from '@angular/core';import {  ScComboboxChip,  ScComboboxChipRemove,  ScComboboxChips,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxMultiple,  ScComboboxPopup,

At most three

Design

1 of 3.

import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import {  ScComboboxChip,  ScComboboxChipRemove,  ScComboboxChips,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,  ScComboboxMultiple,  ScComboboxPopup,

Form

{
  "keywords": []
}
import { JsonPipe } from '@angular/common';import { Component, ViewEncapsulation, computed, signal } from '@angular/core';import { FormField, form, validate } from '@angular/forms/signals';import {  ScComboboxChip,  ScComboboxChipRemove,  ScComboboxChips,  ScComboboxInput,  ScComboboxItem,  ScComboboxList,