Skip to content

Tag Input

Glass chip input: type and press Enter or comma to add gradient chips, Backspace removes the last, × removes one; quick-add suggestion chips and a max counter.

glass/ui/tag-input
Open ↗

Source

"use client";

import { useId, useRef, useState, type KeyboardEvent } from "react";
import { X } from "lucide-react";
import { cn } from "@/lib/utils";

export interface TagInputProps {
  label?: string;
  hint?: string;
  value?: string[];
  defaultValue?: string[];
  onValueChange?: (tags: string[]) => void;
  placeholder?: string;
  /** Suggestions shown as quick-add chips below. */
  suggestions?: string[];
  max?: number;
  className?: string;
}

/** Glass chip input: type and press Enter / comma to add, Backspace to remove the last, click × to remove; quick-add suggestions and a max count. */
export function TagInput({
  label = "Invite participants",
  hint = "Press Enter or comma to add. Halo sends them the recap.",
  value,
  defaultValue = ["amara@lumen.io", "leo@lumen.io"],
  onValueChange,
  placeholder = "name@company.com",
  suggestions = ["sofia@lumen.io", "noah@lumen.io", "jin@lumen.io"],
  max = 10,
  className,
}: TagInputProps) {
  const id = useId();
  const [inner, setInner] = useState(defaultValue);
  const tags = value ?? inner;
  const [draft, setDraft] = useState("");
  const input = useRef<HTMLInputElement>(null);
  const set = (next: string[]) => {
    setInner(next);
    onValueChange?.(next);
  };
  const add = (t: string) => {
    const v = t.trim().replace(/,$/, "");
    if (!v || tags.includes(v) || tags.length >= max) return;
    set([...tags, v]);
    setDraft("");
  };
  const onKey = (e: KeyboardEvent<HTMLInputElement>) => {
    if (e.key === "Enter" || e.key === ",") {
      e.preventDefault();
      add(draft);
    } else if (e.key === "Backspace" && !draft && tags.length) {
      set(tags.slice(0, -1));
    }
  };

  return (
    <div className={cn("grid gap-2", className)}>
      <label htmlFor={id} className="text-sm font-semibold">
        {label}
      </label>
      <div
        onClick={() => input.current?.focus()}
        className="da-stroke flex min-h-12 flex-wrap items-center gap-1.5 rounded-da-md bg-da-input p-2 backdrop-blur-da backdrop-saturate-150 has-focus-visible:ring-(length:--da-ring-width) has-focus-visible:ring-da-ring"
      >
        <ul className="contents" aria-label="Added">
          {tags.map((t) => (
            <li
              key={t}
              className="inline-flex items-center gap-1 rounded-da-pill bg-gradient-to-r from-da-primary to-da-accent py-1 pr-1 pl-3 text-sm font-medium text-da-primary-fg"
            >
              {t}
              <button
                type="button"
                onClick={(e) => {
                  e.stopPropagation();
                  set(tags.filter((x) => x !== t));
                }}
                aria-label={`Remove ${t}`}
                className="da-focus grid size-5 place-items-center rounded-full hover:bg-da-primary-fg/20"
              >
                <X aria-hidden className="size-3" />
              </button>
            </li>
          ))}
        </ul>
        <input
          ref={input}
          id={id}
          value={draft}
          onChange={(e) => setDraft(e.target.value)}
          onKeyDown={onKey}
          onBlur={() => add(draft)}
          placeholder={tags.length ? "" : placeholder}
          disabled={tags.length >= max}
          aria-describedby={`${id}-hint`}
          className="min-w-32 flex-1 bg-transparent px-2 py-1 text-sm outline-none placeholder:text-da-muted-fg"
        />
      </div>
      <p id={`${id}-hint`} className="text-xs text-da-muted-fg">
        {hint} {tags.length}/{max}
      </p>
      {suggestions.filter((s) => !tags.includes(s)).length > 0 && (
        <div className="flex flex-wrap items-center gap-1.5">
          <span className="text-xs text-da-muted-fg">Suggested:</span>
          {suggestions
            .filter((s) => !tags.includes(s))
            .map((s) => (
              <button
                key={s}
                type="button"
                onClick={() => add(s)}
                className="da-focus da-transition da-stroke rounded-da-pill bg-da-surface px-2.5 py-0.5 text-xs hover:bg-da-secondary"
              >
                + {s}
              </button>
            ))}
        </div>
      )}
    </div>
  );
}

export default TagInput;

modules/glass/ui/tag-input/index.tsx

Props

PropTypeDefaultDescription
label / hint / placeholderstring—Texts.
value / defaultValuestring[]—Tags.
onValueChange(tags: string[]) => void—Handler.
suggestionsstring[]—Quick-add.
maxnumber10Limit.
classNamestring—Classes.

Other input variants in Glass

Input in other art directions

Input

Labelled text field with hint, error state, leading icon, suffix slot and two sizes. The field presses into its shadow on focus; errors switch to a red stroke with an explicit message.

BrutalistInput

Number Stepper

Numeric input flanked by chunky yellow − / + buttons (disabled at bounds), big display-font value, optional unit suffix; clamps typed values to min/max.

BrutalistInput

OTP Input

One-time-code input: ruled digit squares (split 3+3 for six digits) that turn yellow and press in on focus; auto-advance, backspace and arrow navigation, paste of the full code, completion callback and error state.

BrutalistInput

Textarea

Labelled multi-line field with a live character counter chip that turns orange near the limit, hint and error states; presses into its shadow on focus.

BrutalistInput

Input

Hairline text field with label (auto "Optional" marker), hint, error with icon, leading icon, text prefix, trailing slot (unit, kbd) and indigo focus ring. Two sizes.

MinimalInput

Search Input

Search field with leading icon, “/” keycap hint that focuses the field, clear button (Escape clears too) and a loading spinner state. Two sizes, controlled or uncontrolled.

MinimalInput

Select Menu

Labelled select built on Radix Select: bordered trigger with chevrons, portalled popover with optional icons, descriptions, groups, separators, disabled items and a check on the selected one.

MinimalInput

Switch Field

Settings row with label and description on the left and a Radix Switch on the right; plain (for divided lists) or bordered card that highlights when on. Disabled state.

MinimalInput

Checkbox Group

Settings checkboxes as ruled rows: square ink check boxes (native inputs), label and muted description; the whole row is clickable.

Mono CleanInput

Input

Underline field: mono uppercase label, a borderless input on a single bottom hairline that turns ink (2px) on focus, optional prefix, hint or red error.

Mono CleanInput

Search Input

Search field with live results: hairline-bordered input with icon and ⌘K hint; matches appear in a ruled list below with the query highlighted and a mono kind label; empty state included.

Mono CleanInput

Select Field

Native select styled as an underline field with a mono label and a custom chevron — reliable on every device and screen reader.

Mono CleanInput

Currency Input

Amount field with currency symbol prefix and an attached currency select; formats with thousands separators on blur, right-aligned mono digits.

Neo CorporateInput

File Upload

Receipt/document dropzone: dashed bordered area with upload icon, click-or-drag, file list with size, per-file size validation errors and remove buttons.

Neo CorporateInput

Input

Form field: label (with optional marker), bordered 40px input with leading/trailing adornments, blue focus ring, hint text or red error with aria-invalid.

Neo CorporateInput

Select Field

Labelled Radix Select styled as a bordered field: grouped options (e.g. GL accounts) with group headings, check on the selected item, portalled popover with data-da.

Neo CorporateInput

Chip Select

Multi-select as soft pill checkboxes: unselected sand pills, selected sage pills with a check that pops in; native checkboxes in a fieldset.

Organic SoftInput

Input

Soft filled text field: rounded sand-filled input that turns cream with a sage ring on focus, optional leading icon and trailing unit, hint or gentle clay error message.

Organic SoftInput

Target Slider

Reduction target picker: a thick rounded sage range (0–60%) with tick labels and a “science-aligned” marker, showing the resulting tonnes and a gentle verdict.

Organic SoftInput

Textarea

Soft note field: rounded sand textarea that auto-grows (field-sizing), with a live character counter that turns clay near the limit.

Organic SoftInput

Checkbox List

Round-checkbox to-do list built on native checkboxes: bouncy mint ticks, strike-through when done, meta line per item and an “x of y” counter with a progress bar.

Soft FlatInput

Day Picker

Week-strip date picker: prev/next week arrows and seven rounded day pills (weekday + number) with task-load dots (red when full); the selected day fills periwinkle.

Soft FlatInput

Input

Soft text field: rounded tinted well that turns white with a thick periwinkle ring on focus, label, optional leading icon and suffix, hint or red error message.

Soft FlatInput

Radio Cards

Native radio group rendered as big pastel cards (emoji, title, text); the chosen card lifts with a periwinkle ring and a filled radio dot.

Soft FlatInput