# Tag input

A controlled native tag field with removable tokens, optional consumer suggestions and form-owned values.

Access: pro. Category: Forms. Kind: primitive.

## When to use

- Use it when a product interface needs a controlled native tag field with removable tokens, optional consumer suggestions and form-owned values.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose form-field instead when a labeled email field with validation and help text is the actual interface need, rather than tag input.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Tag input

```sh
npx shadcn@latest add @tidal-pro/tag-input
```

Stylesheets: `components/ui/tidal.css`, `components/ui/tag-input.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/tag-input.css";
import{TidalTagInput}from"./components/ui/tag-input";
export default()=><div className="tidal-scope"><TidalTagInput label={"Demo"} onQueryChange={() => {}} query={"value"} tags={[{id:"example",value:"value",label:"Demo",accessibleLabel:"Demo"}]}/></div>;
```

## Structured props

- `TidalTagInput.label: ReactNode`: Required label value accepted by this exported component.
- `TidalTagInput.onQueryChange: (value: string, event: ChangeEvent<HTMLInputElement>) => void`: Callback invoked when the query change interaction is proposed.
- `TidalTagInput.query: string`: Required query value accepted by this exported component.
- `TidalTagInput.tags: ReadonlyArray<TidalTagInputTag>`: Required tags value accepted by this exported component.
- `TidalTagInput.description?: ReactNode`: Optional description value accepted by this exported component.
- `TidalTagInput.disabled?: boolean | undefined` (default false): Optional disabled value accepted by this exported component.
- `TidalTagInput.error?: ReactNode`: Optional error value accepted by this exported component.
- `TidalTagInput.form?: string | undefined`: Optional form value accepted by this exported component.
- `TidalTagInput.inputProps?: Omit<InputHTMLAttributes<HTMLInputElement>, "disabled" | "form" | "name" | "type" | "value" | "defaultValue" | "id" | "aria-disabled" | "children" | "readOnly"> | undefined`: Optional input props value accepted by this exported component.
- `TidalTagInput.inputRef?: Ref<HTMLInputElement> | undefined`: Optional input ref value accepted by this exported component.
- `TidalTagInput.labels?: Partial<TidalTagInputLabels> | undefined`: Optional labels value accepted by this exported component.
- `TidalTagInput.maxTags?: number | undefined`: Optional max tags value accepted by this exported component.
- `TidalTagInput.name?: string | undefined`: Optional name value accepted by this exported component.
- `TidalTagInput.onRemoveTag?: ((tag: TidalTagInputTag, event: ReactMouseEvent<HTMLButtonElement> | KeyboardEvent<HTMLInputElement>) => void) | undefined`: Callback invoked when the remove tag interaction is proposed.
- `TidalTagInput.readOnly?: boolean | undefined` (default false): Optional read only value accepted by this exported component.
- `TidalTagInput.status?: ReactNode`: Optional status value accepted by this exported component.
- `TidalTagInput.suggestions?: TidalTagInputSuggestions | undefined`: Optional suggestions value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/tag-input.tsx) | [Manifest](https://tidalui.com/examples/tag-input.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useLayoutEffect, useMemo, useRef, useState, type CSSProperties } from "react";

import { TidalTagInput, type TidalTagInputSuggestion, type TidalTagInputTag } from "./components/ui/tag-input";

import "./components/ui/tag-input.css";



const tidalExampleStyles = ".tidal-scope .tag-input-demo,\n.tidal-scope .tag-input-demo * {\n  box-sizing: border-box;\n}\n\n.tidal-scope .tag-input-demo {\n  width: 100%;\n  min-width: 0;\n  overflow: hidden;\n  border: 1px solid var(--t-border);\n  border-radius: 22px;\n  background:\n    linear-gradient(90deg, var(--t-border) 1px, transparent 1px) 0 0 / 28px 28px,\n    linear-gradient(var(--t-border) 1px, transparent 1px) 0 0 / 28px 28px,\n    var(--t-subtle);\n  color: var(--t-ink);\n  container: tag-input-demo / inline-size;\n}\n\n.tidal-scope .tag-input-demo-layout {\n  display: grid;\n  min-width: 0;\n  grid-template-columns: minmax(0, 1.08fr) minmax(250px, 0.72fr);\n  gap: 14px;\n  padding: 20px;\n}\n\n.tidal-scope .tag-input-demo-editor {\n  min-width: 0;\n  padding: 27px;\n  border: 1px solid var(--t-border);\n  border-radius: 18px;\n  background: var(--t-surface);\n  box-shadow: 0 30px 70px -58px #0000009e;\n}\n\n.tidal-scope .tag-input-demo-heading {\n  display: flex;\n  min-width: 0;\n  align-items: center;\n  justify-content: space-between;\n  gap: 14px;\n}\n\n.tidal-scope .tag-input-demo-heading > span {\n  min-width: 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  font-weight: 740;\n  letter-spacing: 0.12em;\n  line-height: 1.35;\n  text-transform: uppercase;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .tag-input-demo-heading > strong {\n  flex: none;\n  padding: 5px 8px;\n  border: 1px solid var(--t-border);\n  border-radius: 7px;\n  font-size: 11px;\n  font-variant-numeric: tabular-nums;\n  line-height: 1.3;\n}\n\n.tidal-scope .tag-input-demo-editor > h2 {\n  max-width: 16ch;\n  margin: 15px 0 0;\n  font-size: clamp(29px, 5.2cqi, 47px);\n  font-weight: 560;\n  letter-spacing: -0.058em;\n  line-height: 0.98;\n  text-wrap: balance;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .tag-input-demo-editor > p {\n  max-width: 56ch;\n  margin: 13px 0 22px;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.65;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .tag-input-demo-reset {\n  display: inline-flex;\n  min-width: 44px;\n  min-height: 44px;\n  align-items: center;\n  justify-content: center;\n  margin-top: 12px;\n  padding: 8px 13px;\n  border: 1px solid var(--t-border);\n  border-radius: 10px;\n  background: var(--t-surface);\n  color: var(--t-ink);\n  font: inherit;\n  font-size: 11px;\n  font-weight: 680;\n  cursor: pointer;\n  transition:\n    border-color 180ms,\n    background 180ms,\n    transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .tag-input-demo-reset:hover {\n  border-color: var(--t-ink);\n  background: var(--t-subtle);\n}\n\n.tidal-scope .tag-input-demo-reset:active {\n  transform: scale(0.97);\n}\n\n.tidal-scope .tag-input-demo-reset:focus-visible {\n  outline: 2px solid var(--t-accent);\n  outline-offset: 3px;\n}\n\n.tidal-scope .tag-input-demo-board {\n  min-width: 0;\n  align-self: start;\n  padding: 22px;\n  border: 1px solid var(--t-ink);\n  border-radius: 18px;\n  background: var(--t-ink);\n  color: var(--t-surface);\n  box-shadow: 0 32px 70px -54px #000000c4;\n}\n\n.tidal-scope .tag-input-demo-board-head {\n  display: flex;\n  min-width: 0;\n  align-items: center;\n  justify-content: space-between;\n  gap: 14px;\n  padding-bottom: 17px;\n  border-bottom: 1px solid\n    color-mix(in srgb, var(--t-surface) 22%, var(--t-ink));\n}\n\n.tidal-scope .tag-input-demo-board-head > div {\n  min-width: 0;\n}\n\n.tidal-scope .tag-input-demo-board-head > div > span {\n  color: color-mix(in srgb, var(--t-surface) 60%, var(--t-ink));\n  font-size: 11px;\n  font-weight: 700;\n  letter-spacing: 0.1em;\n  line-height: 1.35;\n  text-transform: uppercase;\n}\n\n.tidal-scope .tag-input-demo-board-head h3 {\n  margin: 5px 0 0;\n  font-size: 20px;\n  font-weight: 590;\n  letter-spacing: -0.035em;\n  line-height: 1.1;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .tag-input-demo-board-head > span {\n  display: grid;\n  width: 44px;\n  height: 44px;\n  flex: none;\n  place-items: center;\n  border: 1px solid color-mix(in srgb, var(--t-surface) 28%, var(--t-ink));\n  border-radius: 10px;\n  font-size: 14px;\n  font-variant-numeric: tabular-nums;\n  font-weight: 620;\n}\n\n.tidal-scope .tag-input-demo-board ul {\n  display: grid;\n  gap: 8px;\n  margin: 16px 0 0;\n  padding: 0;\n  list-style: none;\n}\n\n.tidal-scope .tag-input-demo-board li {\n  min-width: 0;\n  padding: 12px;\n  border: 1px solid color-mix(in srgb, var(--t-surface) 20%, var(--t-ink));\n  border-radius: 12px;\n  background: color-mix(in srgb, var(--t-surface) 4%, var(--t-ink));\n  animation: tag-input-row-in 420ms var(--t-ease-out) both;\n  animation-delay: calc(var(--tag-row-index) * 55ms);\n}\n\n.tidal-scope .tag-input-demo-board li > div:first-child {\n  display: flex;\n  min-width: 0;\n  align-items: baseline;\n  justify-content: space-between;\n  gap: 10px;\n}\n\n.tidal-scope .tag-input-demo-board li strong {\n  min-width: 0;\n  font-size: 11px;\n  font-weight: 650;\n  line-height: 1.35;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .tag-input-demo-board li > div:first-child > span {\n  max-width: 44%;\n  color: color-mix(in srgb, var(--t-surface) 62%, var(--t-ink));\n  font-size: 11px;\n  line-height: 1.35;\n  text-align: end;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .tag-input-demo-progress {\n  height: 4px;\n  margin-top: 10px;\n  overflow: hidden;\n  border-radius: 999px;\n  background: color-mix(in srgb, var(--t-surface) 18%, var(--t-ink));\n}\n\n.tidal-scope .tag-input-demo-progress > span {\n  display: block;\n  height: 100%;\n  border-radius: inherit;\n  background: var(--t-surface);\n  transform-origin: left center;\n  animation: tag-input-progress-in 620ms var(--t-ease-out) both;\n}\n\n.tidal-scope[dir=\"rtl\"] .tag-input-demo-progress > span {\n  transform-origin: right center;\n}\n\n.tidal-scope .tag-input-demo-empty {\n  display: grid;\n  min-height: 184px;\n  place-content: center;\n  gap: 6px;\n  text-align: center;\n}\n\n.tidal-scope .tag-input-demo-empty strong {\n  font-size: 12px;\n}\n\n.tidal-scope .tag-input-demo-empty span {\n  color: color-mix(in srgb, var(--t-surface) 64%, var(--t-ink));\n  font-size: 11px;\n  line-height: 1.45;\n}\n\n@container tag-input-demo (max-width: 760px) {\n  .tidal-scope .tag-input-demo-layout {\n    grid-template-columns: minmax(0, 1fr);\n    padding: 10px;\n  }\n\n  .tidal-scope .tag-input-demo-editor {\n    padding: 21px;\n  }\n\n  .tidal-scope .tag-input-demo-board {\n    padding: 18px;\n  }\n}\n\n@container tag-input-demo (max-width: 390px) {\n  .tidal-scope .tag-input-demo-layout {\n    gap: 8px;\n    padding: 6px;\n  }\n\n  .tidal-scope .tag-input-demo-editor,\n  .tidal-scope .tag-input-demo-board {\n    padding: 15px;\n  }\n\n  .tidal-scope .tag-input-demo-editor > h2 {\n    font-size: 29px;\n  }\n}\n\n@keyframes tag-input-row-in {\n  from {\n    opacity: 0;\n    transform: translateY(7px);\n  }\n}\n\n@keyframes tag-input-progress-in {\n  from {\n    transform: scaleX(0);\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .tag-input-demo-board li,\n  .tidal-scope .tag-input-demo-progress > span {\n    animation: none;\n  }\n\n  .tidal-scope .tag-input-demo-reset {\n    transition: none;\n  }\n\n  .tidal-scope .tag-input-demo-reset:active {\n    transform: none;\n  }\n}";

const ALL_TAGS: readonly TidalTagInputTag[] = [
  { id: "review", value: "review", label: "Review", accessibleLabel: "Review" },
  { id: "design", value: "design", label: "Design", accessibleLabel: "Design" },
  { id: "copy", value: "copy", label: "Copy", accessibleLabel: "Copy" },
  {
    id: "blocked",
    value: "blocked",
    label: "Blocked",
    accessibleLabel: "Blocked",
  },
  { id: "ready", value: "ready", label: "Ready", accessibleLabel: "Ready" },
];

const SAMPLE_ITEMS = [
  {
    id: "brief",
    title: "Project brief",
    tags: ["review", "copy"],
    progress: 72,
  },
  {
    id: "landing",
    title: "Landing page",
    tags: ["review", "design"],
    progress: 48,
  },
  { id: "launch", title: "Launch checklist", tags: ["ready"], progress: 100 },
  {
    id: "notes",
    title: "Interview notes",
    tags: ["blocked", "copy"],
    progress: 24,
  },
] as const;

export function TagInputDemo() {
  const [tags, setTags] = useState<readonly TidalTagInputTag[]>([
    ALL_TAGS[0],
    ALL_TAGS[1],
  ]);
  const [query, setQuery] = useState("");
  const [message, setMessage] = useState("Two labels selected.");
  const inputRef = useRef<HTMLInputElement>(null);
  const pendingInputFocus = useRef(false);

  useLayoutEffect(() => {
    if (!pendingInputFocus.current) return;
    pendingInputFocus.current = false;
    inputRef.current?.focus({ preventScroll: true });
  }, [tags]);

  const suggestions = useMemo(
    () =>
      ALL_TAGS.filter(
        (candidate) =>
          !tags.some((tag) => tag.id === candidate.id) &&
          candidate.accessibleLabel.toLowerCase().includes(query.toLowerCase()),
      ),
    [query, tags],
  );
  const visibleItems = useMemo(
    () =>
      SAMPLE_ITEMS.filter(
        (item) =>
          tags.length === 0 ||
          tags.some((tag) => item.tags.includes(tag.value as never)),
      ),
    [tags],
  );

  const selectSuggestion = (suggestion: TidalTagInputSuggestion) => {
    const tag = ALL_TAGS.find((candidate) => candidate.id === suggestion.id);
    if (!tag) return;
    setTags((current) => [...current, tag]);
    setQuery("");
    setMessage(`${tag.accessibleLabel} added.`);
    inputRef.current?.focus({ preventScroll: true });
  };

  return (
    <section className="tag-input-demo" aria-label="Project label preview">
      <div className="tag-input-demo-layout">
        <div className="tag-input-demo-editor">
          <div className="tag-input-demo-heading">
            <span>Review queue</span>
            <strong>{visibleItems.length} visible</strong>
          </div>
          <TidalTagInput
            label="Project labels"
            description="Choose up to five labels."
            tags={tags}
            query={query}
            maxTags={5}
            inputRef={inputRef}
            inputProps={{ placeholder: "Find a label" }}
            onQueryChange={(value) => setQuery(value)}
            onRemoveTag={(tag) => {
              pendingInputFocus.current = true;
              setTags((current) =>
                current.filter((candidate) => candidate.id !== tag.id),
              );
              setMessage(`${tag.accessibleLabel} removed.`);
            }}
            suggestions={{
              label: query ? `Suggestions for “${query}”` : "Available labels",
              accessibleLabel: "Available project labels",
              items: suggestions,
              onSelect: selectSuggestion,
            }}
            status={
              <span role="status" aria-live="polite">
                {message} Sample data. Changes stay in this preview.
              </span>
            }
          />

          <button
            type="button"
            className="tag-input-demo-reset"
            onClick={() => {
              setTags([ALL_TAGS[0], ALL_TAGS[1]]);
              setQuery("");
              setMessage("Labels reset.");
              inputRef.current?.focus({ preventScroll: true });
            }}
          >
            Reset labels
          </button>
        </div>

        <section className="tag-input-demo-board" aria-label="Filtered work">
          <div className="tag-input-demo-board-head">
            <div>
              <span>Tasks</span>
              <h3>Review queue</h3>
            </div>
            <span>{visibleItems.length.toString().padStart(2, "0")}</span>
          </div>
          {visibleItems.length ? (
            <ul>
              {visibleItems.map((item, index) => (
                <li
                  key={item.id}
                  style={{ "--tag-row-index": index } as CSSProperties}
                >
                  <div>
                    <strong>{item.title}</strong>
                    <span>{item.tags.join(" · ")}</span>
                  </div>
                  <div
                    className="tag-input-demo-progress"
                    role="img"
                    aria-label={`${item.progress}% complete`}
                  >
                    <span style={{ width: `${item.progress}%` }} />
                  </div>
                </li>
              ))}
            </ul>
          ) : (
            <div className="tag-input-demo-empty">
              <strong>No matching tasks.</strong>
              <span>Remove a label or reset the filters.</span>
            </div>
          )}
        </section>
      </div>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <TagInputDemo />
    </div>
  );
}

```

## Gotchas

- Keep field state, validation results, submission, and persistence in the host form workflow.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order.","Arrow-key behavior follows the exported composite-control implementation."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

label, controlled tags/query and onQueryChange are required. Each tag has a stable id, submitted value, visible ReactNode label and accessibleLabel, with optional disabled removal. Consumers own filtering, validation, suggestions, persistence and every state mutation. Optional onRemoveTag enables 44px remove controls and empty-query Backspace removal of the last enabled tag; caller key prevention and IME composition suppress it. Optional suggestions are native 44px buttons whose supplied click runs before onSelect and may prevent it; no combobox behavior is claimed. Optional name/form render one hidden successful control per selected tag; disabled excludes them while readOnly keeps them submitted. maxTags disables additions but does not mutate caller tags. Description/error/status and external input aria-describedby compose. Native root/input attributes and refs remain available; inputProps excludes value/defaultValue/name/id/type/disabled/readOnly/form/aria-disabled because the component owns those contracts. The component performs no request, routing, storage, analytics, tag creation or persistence.
