# Item tags

Tag list items with names that mean something to your app, then style them and
change how they react to input. The components never interpret a tag: they only
expose it and apply the generic interaction flags you declare for it.

Works the same on `ixfx-grid-list`, `ixfx-detail-list`, `ixfx-data-grid` and
`ixfx-multicol-list` (and on `ixfx-vertical-list`, which `ixfx-multicol-list` uses for its columns).

## 1. Assigning tags

Two forms, which can be combined (tags are merged, de-duplicated):

| Form | Where |
| --- | --- |
| Hook returning `readonly string[] \| undefined` | `ixfx-grid-list`: `itemAdapter.tags(item, index)`. `ixfx-detail-list` / `ixfx-data-grid`: `list.tags(item, index)`. `ixfx-multicol-list`: `list.tags(item, columnId)` |
| Key sets: `tagKeys: ReadonlyMap<tag, ReadonlySet<key>>` | all of them (`ixfx-vertical-list` too). For tags kept apart from the item data, like `partialKeys`. Works for light-DOM / element-mode items |

```ts
grid.itemAdapter = { key, render, tags: row => row.willBeRemoved ? [`leaving`] : undefined };
grid.tagKeys = new Map([[`arriving`, new Set([`k1`, `k2`])]]);
```

Tags are re-read on every render, so `updateItem` / `updateItems` (grid-list) and
assigning `items` / `rows` pick up changes without rebuilding the adapter. If a hook reads
state outside the items, call `refreshTags()` (detail-list, data-grid, multicol-list).
Empty names and names containing whitespace are ignored.

## 2. Styling

Each tag is exposed on the item:

- `data-tags` (space separated): `[data-tags~="leaving"]`. Always present.
- a `part` token `tag-<name>` on shadow-DOM items: `::part(item tag-leaving)`.

The prefix keeps a caller tag called `selected` from colliding with the built-in state.

Which element carries what:

| Component | Item element (background, `part="item …"`) | Content |
| --- | --- | --- |
| `ixfx-grid-list` | `.cell` — `part="item"` | `part="content"` inside it |
| `ixfx-data-grid` | `.row` — `part="item"` | the `.cell` children (`part="cell"`-style cells) |
| `ixfx-detail-list` | the light-DOM `<li>` (`data-tags` only — it is not in a shadow tree, so no `part`) | the `<li>`'s children |
| `ixfx-multicol-list` / `ixfx-vertical-list` | the light-DOM `<li>` (`data-tags` only) | the `<li>`'s children |

```css
ixfx-grid-list::part(item tag-leaving) { opacity: 0.5; text-decoration: line-through; }
ixfx-detail-list li[data-tags~="arriving"] { background: color-mix(in srgb, green 15%, transparent); }
```

## 3. Behaviour

```ts
list.tagBehaviour = {
  leaving: { selectable: false, focusable: false, draggable: false, searchable: false },
};
```

- Flags left out keep the default. A tag with no declaration only styles.
- Several tags: the most restrictive wins (any `false` beats `true`).
- `selectable: false` — no selection or tickle, no `list-select-intent`; range, marquee and select-all skip the item.
- `focusable: false` — keyboard cursor movement skips the item (hover can still tickle it).
- `draggable: false` — no drag starts from the item.
- `searchable: false` — left out of incremental search.
- `reorderable: false` — can't be moved by drag-to-reorder (`items-reorderable`). It is left out of a dragged block, so the rest of a multi-selection still moves, and a gap next to it can still be targeted. See [Drops and drag-to-reorder](./user-list-drop.md).
- The item is always still rendered and still counts for layout and scroll position.

`ixfx-grid-list`'s `disabled` adapter hook is unchanged and combines with these flags.
