# @salmonui/buttons/tag-group API reference

> 16 exported symbols of @salmonui/buttons/tag-group: 3 functions, 9 interfaces and 4 types.

Canonical: https://salmonui.dev/docs/reference/buttons/tag-group

```ts
import { … } from '@salmonui/buttons/tag-group';
```

## Functions

### Tag

Kind: function

Page: https://salmonui.dev/docs/reference/buttons/tag-group/Tag

```ts
function Tag(props: TagProps): ReactElement;
```

One tag: `.salmon-tag` row with a single cell (label, icons, remove button).

### TagGroup

Kind: function

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagGroup

```ts
function TagGroup(props: TagGroupProps): ReactElement;
```

A wrapping collection of tags: `.salmon-tag-group` (`role="grid"`) of
`Tag` rows, one tab stop, arrow keys mirrored in RTL.

### moveTags

Kind: function

Page: https://salmonui.dev/docs/reference/buttons/tag-group/moveTags

```ts
function moveTags<T>(list: readonly T[], values: readonly string[], toIndex: number, getValue?: (item: T) => string): T[];
```

Moves the entries whose value is in `values` to the insertion index
`toIndex` of `list` (an index in the current order, before the moved
entries are removed), keeping their relative order. A cross-group drop
(`onTagDrop`) is a filter on the source and a splice on the target.

## Interfaces

### TagDragEndEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagDragEndEvent

```ts
interface TagDragEndEvent {
    readonly values: readonly string[];
    readonly dropped: boolean;
}
```

`onTagDragEnd` event on the source group.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `values` | `readonly values: readonly string[];` |  |  |
| `dropped` | `readonly dropped: boolean;` |  |  |

### TagDragEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagDragEvent

```ts
interface TagDragEvent {
    readonly values: readonly string[];
    readonly clientX: number;
    readonly clientY: number;
    readonly toIndex: number | null;
    readonly overGroup: string | null;
}
```

`onTagDrag` event, at most once per animation frame.

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `values` | `readonly values: readonly string[];` |  |  |
| `clientX` | `readonly clientX: number;` |  |  |
| `clientY` | `readonly clientY: number;` |  |  |
| `toIndex` | `readonly toIndex: number \| null;` |  | Insertion index in the group under the pointer, or null outside any accepting group. |
| `overGroup` | `readonly overGroup: string \| null;` |  | `dragGroup` of the group under the pointer (null outside, or a group without one). |

### TagDragStartEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagDragStartEvent

```ts
interface TagDragStartEvent {
    readonly values: readonly string[];
    readonly source: TagEventSource;
    preventDefault(): void;
    readonly defaultPrevented: boolean;
}
```

`onTagDragStart` event; `preventDefault()` cancels the drag.

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `values` | `readonly values: readonly string[];` |  |  |
| `source` | `readonly source: TagEventSource;` |  |  |
| `preventDefault` | `preventDefault(): void;` |  |  |
| `defaultPrevented` | `readonly defaultPrevented: boolean;` |  |  |

### TagDropEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagDropEvent

```ts
interface TagDropEvent {
    readonly values: readonly string[];
    readonly fromGroup: string;
    readonly toIndex: number;
    readonly source: TagEventSource;
}
```

`onTagDrop` event, fired on the receiving group of a cross-group drop.

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `values` | `readonly values: readonly string[];` |  |  |
| `fromGroup` | `readonly fromGroup: string;` |  | `id` of the source group (its `id` prop, or a generated id). |
| `toIndex` | `readonly toIndex: number;` |  |  |
| `source` | `readonly source: TagEventSource;` |  |  |

### TagGroupProps

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagGroupProps

```ts
interface TagGroupProps extends Omit<HTMLAttributes<HTMLDivElement>, 'defaultValue' | 'onChange' | 'role' | 'onDrag' | 'onDragStart' | 'onDragEnd' | 'onDrop'> {
    children?: ReactNode;
    selectionMode?: TagSelectionMode | undefined;
    value?: readonly string[] | undefined;
    defaultValue?: readonly string[] | undefined;
    onValueChange?: ((value: readonly string[], event: TagSelectionEvent) => void) | undefined;
    onRemove?: ((values: readonly string[], event: TagRemoveEvent) => void) | undefined;
    reorderable?: boolean | undefined;
    onReorder?: ((event: TagReorderEvent) => void) | undefined;
    dragGroup?: string | undefined;
    onTagDrop?: ((event: TagDropEvent) => void) | undefined;
    onTagDragStart?: ((event: TagDragStartEvent) => void) | undefined;
    onTagDrag?: ((event: TagDragEvent) => void) | undefined;
    onTagDragEnd?: ((event: TagDragEndEvent) => void) | undefined;
    disabled?: boolean | undefined;
    tone?: TagTone | undefined;
    size?: TagSize | undefined;
    name?: string | undefined;
    empty?: ReactNode;
    localeText?: {
        readonly remove?: ((label: string) => string) | undefined;
    } | undefined;
    ref?: Ref<HTMLDivElement> | undefined;
}
```

Members (20):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `children` | `children?: ReactNode;` | optional | `Tag` elements; map your array to them (add = append, remove = filter). |
| `selectionMode` | `selectionMode?: TagSelectionMode \| undefined;` | optional | Default `'none'`; selectable rows carry `aria-selected`. |
| `value` | `value?: readonly string[] \| undefined;` | optional | Selected tag values (at most one in single mode). |
| `defaultValue` | `defaultValue?: readonly string[] \| undefined;` | optional |  |
| `onValueChange` | `onValueChange?: ((value: readonly string[], event: TagSelectionEvent) => void) \| undefined;` | optional |  |
| `onRemove` | `onRemove?: ((values: readonly string[], event: TagRemoveEvent) => void) \| undefined;` | optional | Makes tags removable: a remove button and Delete / Backspace. Remove the values from your state; not removing them vetoes. |
| `reorderable` | `reorderable?: boolean \| undefined;` | optional | Pointer drag within the group and Alt + arrow keys fire `onReorder`. |
| `onReorder` | `onReorder?: ((event: TagReorderEvent) => void) \| undefined;` | optional |  |
| `dragGroup` | `dragGroup?: string \| undefined;` | optional | Groups with the same `dragGroup` accept each other's tags; the receiving group fires `onTagDrop`. |
| `onTagDrop` | `onTagDrop?: ((event: TagDropEvent) => void) \| undefined;` | optional |  |
| `onTagDragStart` | `onTagDragStart?: ((event: TagDragStartEvent) => void) \| undefined;` | optional |  |
| `onTagDrag` | `onTagDrag?: ((event: TagDragEvent) => void) \| undefined;` | optional |  |
| `onTagDragEnd` | `onTagDragEnd?: ((event: TagDragEndEvent) => void) \| undefined;` | optional |  |
| `disabled` | `disabled?: boolean \| undefined;` | optional | Disables every tag; nothing is submitted while disabled. |
| `tone` | `tone?: TagTone \| undefined;` | optional | Default tone of the tags. |
| `size` | `size?: TagSize \| undefined;` | optional |  |
| `name` | `name?: string \| undefined;` | optional | Form field name: hidden inputs with the selected values (selectable), else every tag's value. |
| `empty` | `empty?: ReactNode;` | optional | Shown in a single row when there are no tags. |
| `localeText` | `localeText?: {     readonly remove?: ((label: string) => string) \| undefined; } \| undefined;` | optional |  |
| `ref` | `ref?: Ref<HTMLDivElement> \| undefined;` | optional |  |

### TagProps

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagProps

```ts
interface TagProps extends Omit<HTMLAttributes<HTMLDivElement>, 'role' | 'children'> {
    value: string;
    children?: ReactNode;
    textValue?: string | undefined;
    iconStart?: ReactNode;
    iconEnd?: ReactNode;
    tone?: TagTone | undefined;
    disabled?: boolean | undefined;
    removable?: boolean | undefined;
    ref?: Ref<HTMLDivElement> | undefined;
}
```

Members (9):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `value` | `value: string;` |  | Stable identity, reported in every event and submitted with `name`. |
| `children` | `children?: ReactNode;` | optional |  |
| `textValue` | `textValue?: string \| undefined;` | optional | Plain-text label when `children` is not a string (remove button name). |
| `iconStart` | `iconStart?: ReactNode;` | optional |  |
| `iconEnd` | `iconEnd?: ReactNode;` | optional |  |
| `tone` | `tone?: TagTone \| undefined;` | optional |  |
| `disabled` | `disabled?: boolean \| undefined;` | optional |  |
| `removable` | `removable?: boolean \| undefined;` | optional | `false` opts this tag out of removal. Default: removable when the group has `onRemove`. |
| `ref` | `ref?: Ref<HTMLDivElement> \| undefined;` | optional |  |

### TagRemoveEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagRemoveEvent

```ts
interface TagRemoveEvent {
    readonly source: TagEventSource;
    readonly reason: 'button' | 'delete' | 'backspace';
}
```

`onRemove` event: the remove button, or Delete / Backspace on the focused tag.

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: TagEventSource;` |  |  |
| `reason` | `readonly reason: 'button' \| 'delete' \| 'backspace';` |  |  |

### TagReorderEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagReorderEvent

```ts
interface TagReorderEvent {
    readonly values: readonly string[];
    readonly toIndex: number;
    readonly delta: number | null;
    readonly source: TagEventSource;
}
```

`onReorder` event; apply it with `moveTags(list, values, toIndex)`.

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `values` | `readonly values: readonly string[];` |  |  |
| `toIndex` | `readonly toIndex: number;` |  | Insertion index in the current order (before the moved tags are removed). |
| `delta` | `readonly delta: number \| null;` |  | `-1` / `1` for a keyboard step (Alt + arrow), null for a drop. |
| `source` | `readonly source: TagEventSource;` |  |  |

### TagSelectionEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagSelectionEvent

```ts
interface TagSelectionEvent {
    readonly source: TagEventSource;
    readonly reason: 'toggle' | 'reset';
}
```

`onValueChange` event: `reason` is `'toggle'` or `'reset'` (form reset).

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: TagEventSource;` |  |  |
| `reason` | `readonly reason: 'toggle' \| 'reset';` |  |  |

## Types

### TagEventSource

Kind: type

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagEventSource

```ts
type TagEventSource = PressSource | 'api';
```

### TagSelectionMode

Kind: type

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagSelectionMode

```ts
type TagSelectionMode = 'none' | 'single' | 'multiple';
```

### TagSize

Kind: type

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagSize

```ts
type TagSize = 'sm' | 'md' | 'lg';
```

One of three fixed metric sets (the Button sizes).

### TagTone

Kind: type

Page: https://salmonui.dev/docs/reference/buttons/tag-group/TagTone

```ts
type TagTone = 'neutral' | 'primary' | 'success' | 'warning' | 'danger' | 'info';
```

Color role of a tag (the Button tones).
