# `ixfx-tag-list`

Shows tags as a horizontally wrapping flow, and lets the user add and remove them. Supports "indeterminate" tags for representing a set of data where only some of it has the tag.

```html
<ixfx-tag-list editing="all" allow-new></ixfx-tag-list>
<script type="module">
  const el = document.querySelector('ixfx-tag-list');
  el.tags = ['design', { value: 'urgent', indeterminate: true }];
  el.options = ['design', 'engineering', 'urgent', 'bug'];
</script>
```

## Attributes

| Attribute | Type | Default | Description |
|---|---|---|---|
| `editing` | `all \| add \| delete \| readonly` | `all` | What the user may change |
| `delete-mode` | `button \| menu` | `button` | How tags are deleted |
| `allow-new` | boolean | — | Let the user type tags that are not in `options` |
| `search-placeholder` | string | `Find or add tag…` | Placeholder of the add-tag search box |

### `editing`

| Value | Add (`+`) | Delete | Turn indeterminate tag on |
|---|---|---|---|
| `readonly` | no | no | no |
| `delete` | no | yes | no |
| `add` | yes | no | yes |
| `all` | yes | yes | yes |

### `delete-mode`

- `button` — a small X after each tag; tapping it removes the tag.
- `menu` — tapping a tag opens a popover with **Delete**. When `editing="all"` and `allow-new` are both set it also offers **Rename**, which swaps the popover for a text box (Enter to commit, Escape to cancel). Right-click, Enter/Space and Delete also open it.
  - Tapping an *indeterminate* tag turns it on instead of opening the menu; right-click or the Delete key still reach its menu.
  - Rename is only available in `menu` mode.

## JavaScript properties

| Property | Type | Description |
|---|---|---|
| `tags` | `(string \| { value, label?, indeterminate? })[]` | Tags shown. Identity is `value`, compared case-insensitively. The component updates this itself when the user edits. |
| `validate` | `(value, { kind, previous, tags }) => true \| false \| string` | Checks typed-in tag names: new tags (`kind: 'add'`) and renames (`kind: 'rename'`). Return `true`/nothing to accept, `false` to reject, or a string to reject with that message. Shown inline; the tag isn't added until it passes. Empty names and (for renames) duplicates are rejected first. Tags picked from `options` aren't validated. Synchronous. |
| `options` | `(string \| { value, label? })[]` | Suggestions listed when adding. Tags already on are left out. |

## Adding

When adding is allowed, a dashed `+` tag follows the tags. Tapping it opens a popover with a focused search box and the list of `options`, narrowed with a fuzzy search as the user types. Arrow keys move, Enter picks, Escape closes. With `allow-new`, an `Add "text"` row appears when the text doesn't match an existing tag or option.

## Indeterminate tags

`{ value: 'urgent', indeterminate: true }` shows a dashed, muted tag. Tapping it (or Enter / Space) turns it on and fires `tag-activate`. Removing an indeterminate tag removes it entirely. Indeterminate tags still appear in the options list; picking one turns it on.

## Events

| Event | Detail | When |
|---|---|---|
| `tag-add` | `{ value, label, isNew }` | A tag was added |
| `tag-remove` | `{ value }` | A tag was removed |
| `tag-rename` | `{ from, to }` | A tag was renamed |
| `tag-activate` | `{ value }` | An indeterminate tag was turned on |
| `change` | `{ tags }` | After any of the above, with the full new list |

## CSS custom properties

`--tag-list-gap`, `--tag-list-height`, `--tag-list-radius`, `--tag-list-bg`, `--tag-list-text`, `--tag-list-indeterminate-text`. Otherwise styled from the theme variables ([infra-theming](./infra-theming.md)).

The `part`s `tag` and `add-tag` are exposed for styling.
