# Tag Input (`<z-input-tag>`)

> Token input that turns typed text into removable, editable tags, with validation, slugify, and duplicate control.

- **Kind:** hwc
- **Category:** inputs
- **Inherits:** `InputMixin`, `Hwc`, `Base`

## Attributes

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `maxlength` | `number` | `20` | — | Maximum characters per tag (default 20). |
| `minlength` | `number` | `1` | — | Minimum characters per tag (default 1). |
| `slugify` | `boolean` | `false` | — | Slugifies tag values (lowercase, hyphenated) before committing. |
| `slugify-options` | `string` | `''` | — | JSON options passed to the slugify helper (e.g. replacement characters). |
| `delimiters` | `string` | `','` | — | Characters that commit the current text as a tag (default `,`). |
| `allow-duplicates` | `boolean` | `false` | — | Allows the same tag more than once. |
| `max-tags` | `number` | `0` | — | Maximum number of tags (0 = unlimited). |
| `add-on-blur` | `boolean` | `true` | — | Commits the pending text as a tag when the input loses focus (default true). |

### Inherited from `InputMixin`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `disabled` | `boolean` | `false` | `InputMixin` | Disables the control so it cannot be interacted with. |
| `form` | `string` | `''` | `InputMixin` | Associates the hidden form input with a form by id, even when the component sits outside that form. |
| `name` | `string` | `''` | `InputMixin` | Field name for the hidden form input; array values submit as `name[]`. |
| `placeholder` | `string` | `''` | `InputMixin` | Placeholder text for the control's empty state. |
| `required` | `boolean` | `false` | `InputMixin` | Marks the control as required. |
| `value` | `string` | `''` | `InputMixin` | Initial value of the control, synchronized with the hidden form input. |

### Inherited from `Hwc`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `i18n` | `string` | `''` | `Hwc` | Per-instance text overrides as `key: text` pairs, merged over the global `z-i18n` script and the built-in defaults. |
| `floating` | `string` | `''` | `Hwc` | Floating UI placement options (for example `offset` and `shiftPadding`) parsed as `key: value` pairs. |
| `force-prevent-rerender` | `boolean` | `false` | `Hwc` | Skips re-rendering after the first render; an existing `data-host-inner` child is adopted as the rendered DOM. |
| `template` | `string` | `''` | `Hwc` | Selector or id of an external element or `<template>` whose inner content is cloned in place of an inline `template[data-fn="template"]` child. |

### Inherited from `Base`

| Attribute | Type | Default | From | Description |
| --- | --- | --- | --- | --- |
| `cls` | `string` | `''` | `Base` | Adds classes to named parts as `key: classes` pairs; a plain string targets the default part. |
| `stl` | `string` | `''` | `Base` | Adds inline styles to named parts as `key: styles` pairs; a plain string targets the default part. |

## Styling Parts (`cls` / `stl`)

Default `cls` target: `wrapper`. Default `stl` target: `wrapper`.

| Key | Default class | cls | stl | Description |
| --- | --- | --- | --- | --- |
| `error` | `sr-only` | ✓ | ✓ | Validation message region (default `sr-only`). |
| `host-inner` | — | ✓ | ✓ | Rendered root wrapper. |
| `input` | — | ✓ | ✓ | The text input for new tags. |
| `tag` | `z-tag z-tag-secondary` | ✓ | — | One tag chip (default `z-tag z-tag-secondary`). |
| `tag-list` | `z-input-tag-list` | ✓ | ✓ | List of committed tags (default `z-input-tag-list`). |
| `tag-remove` | — | ✓ | — | Tag remove button. |
| `tag-text` | — | ✓ | — | Tag label, click to edit (button role). |
| `wrapper` | `z-input-tag` | ✓ | ✓ | The tag field wrapper (default `z-input-tag`); the default `cls`/`stl` target. |

## Reference inventories

- [CSS Variables (15)](https://next.0build.dev/docs/components/input-tag/css-vars.md)
- [CSS Classes (2)](https://next.0build.dev/docs/components/input-tag/css-classes.md)
- [Accessibility (8 ARIA parts)](https://next.0build.dev/docs/components/input-tag/accessibility.md)

## i18n Keys

| Key | Default | Description |
| --- | --- | --- |
| `duplicate-error` | `Tag already exists` | Error shown for a duplicate tag. |
| `edit-label` | `Edit tag` | Prefix of the edit-tag button label. |
| `input-label` | `Tag input` | Accessible label of the tag input. |
| `max-length-error` | `Tag cannot exceed {max} characters` | Error template with `{max}` for too-long tags. |
| `max-tags-error` | `Maximum {max} tags allowed` | Error template with `{max}` when the tag limit is reached. |
| `min-length-error` | `Tag must be at least {min} characters` | Error template with `{min}` for too-short tags. |
| `placeholder` | `Add a tag...` | Placeholder of the tag input. |
| `remove-label` | `Remove tag` | Prefix of the remove-tag button label. |
| `tag-list-label` | `Tags` | Accessible label of the tag list. |

## Events

| Event | Cancelable | Detail | Description |
| --- | --- | --- | --- |
| `z-input-tag:input` | — | `{ value: string \| string[] }` | Fires when the tag list changes; `detail.value` carries the tags as a string array. |

## Data Hooks

| Attribute | Values | Applies to | Role | Description |
| --- | --- | --- | --- | --- |
| `data-disabled` | — | `descendant` | `marker` | Set on the wrapper while the control is disabled. |
| `data-has-error` | — | `descendant` | `marker` | Set on the wrapper while a validation error is shown. |
| `data-host-inner` | — | `descendant` | `config` | Marks the rendered inner wrapper so `force-prevent-rerender` can adopt server-rendered DOM without re-rendering. |
| `data-reactive` | — | `descendant` | `config` | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |
| `data-tag-index` | — | `descendant` | `marker` | Set by the component on each tag to its index. |

## Child Content

- `<script data-fn="config">` — JSON configuration script parsed by the base class (i18n, cls, stl, floating).

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `config` | Marks the script as configuration (value: `config`). |
  | `data-reactive` | — | `boolean` | Re-parses the configuration when the script mutates. |

- `<select data-fn="data-source">` — Hidden select parsed into grouped option data by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `data-source` | Marks the select as the data source (value: `data-source`). |
  | `data-reactive` | — | `boolean` | Re-parses the options when the select mutates. |

  - `<optgroup>` — Groups options under a label.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `label` | ✓ | `string` | Group header text; also the default group key. |
    | `disabled` | — | `boolean` | Disables every option in the group. |
    | `data-key` | — | `string` | Overrides the group key used in the parsed data. |
    | `data-keywords` | — | `comma-separated string` | Comma-separated keywords stored with the group's data. |

    - `<option>` — One option entry within the group.

      | Attribute | Required | Type | Description |
      | --- | --- | --- | --- |
      | `value` | — | `string` | Value carried by this option in the parsed data. |
      | `disabled` | — | `boolean` | Makes the option non-selectable. |
      | `selected` | — | `boolean` | Marks the option as initially selected. |
      | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated; searched alongside the label and value. |

  - `<option>` — One ungrouped option entry.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `value` | — | `string` | Value carried by this option in the parsed data. |
    | `disabled` | — | `boolean` | Makes the option non-selectable. |
    | `selected` | — | `boolean` | Marks the option as initially selected. |
    | `data-keywords` | — | `comma-separated string` | Extra search terms, comma-separated. |

- `<template data-fn="icons">` — Instance-level icon repository.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `icons` | Marks the template as an icon source (value: `icons`). |
  | `data-reactive` | — | `boolean` | Re-parses the icons when the template mutates. |

  - `<*>` — One icon element.

    | Attribute | Required | Type | Description |
    | --- | --- | --- | --- |
    | `data-key` | ✓ | `string` | Icon key referenced by `$icons`. |

- `<template data-fn="template">` — Deferred content template mounted by the base class.

  | Attribute | Required | Type | Description |
  | --- | --- | --- | --- |
  | `data-fn` | ✓ | `template` | Marks the template for deferred mounting (value: `template`). |
  | `data-reactive` | — | `boolean` | Re-parses the template when it mutates. |

## Keyboard

| Keys | Action | When |
| --- | --- | --- |
| `Enter` | Commits the pending text as a tag. | — |
| `Backspace` | Removes the last tag when the input is empty. | The input is empty. |

## Notes

- Tags are committed on delimiter characters, Enter, or blur (when `add-on-blur`); clicking a tag's text edits it in place.
- Length, duplicate, and count violations show the matching i18n error and block the commit.

## Guides

- [Styling with cls and stl](https://next.0build.dev/docs/guides/styling.md)
- [Translating Components](https://next.0build.dev/docs/guides/i18n.md)
- [Icon Resolution](https://next.0build.dev/docs/guides/icons.md)
- [The data-source Convention](https://next.0build.dev/docs/guides/data-source.md)
- [Openers & Triggers](https://next.0build.dev/docs/guides/triggers.md)
- [Dialog Behavior](https://next.0build.dev/docs/guides/dialogs.md)
- [Utilities](https://next.0build.dev/docs/guides/utilities.md)
- [Runtime](https://next.0build.dev/docs/guides/runtime.md)

## Related

- [Select](https://next.0build.dev/docs/components/select.md)
- [PIN Input](https://next.0build.dev/docs/components/input-pin.md)
