# Tag

A short status or category label, such as Paid, Overdue or Beta, with an optional icon, a pill shape and a remove button.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-tag`, `[vigChipIcon]`
- Source: [libs/ui/src/lib/atoms/chip/chip.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/atoms/chip/chip.ts)

```typescript title="Import"
import { Chip, ChipIcon } from '@vigdx/ui/chip';
```

> **Note: An alias of vig-chip**
>
> `vig-tag` is a second selector of the `Chip` component, so import `Chip` to use it. Both take the same inputs, tokens and remove button; see [Chip](https://vigdx.com/components/chip.md). Use a [badge](https://vigdx.com/components/badge.md) for counts and pill-shaped status dots.

## Variants and icons

`variant` takes the shared variants (`success`, `warning`, `error`, `info`, `primary`, `secondary` …) plus `accent`. Mark a leading icon with `vigChipIcon`: any icon works, sized at 1em and hidden from assistive tech.

```typescript title="tag-severities.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Chip, ChipIcon } from '@vigdx/ui/chip';
import { Icon } from '@vigdx/ui/icon';

@Component({
  selector: 'app-tag-severities',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Chip, ChipIcon, Icon],
  template: `
    <div class="flex flex-wrap items-center gap-2">
      <vig-tag label="Paid" variant="success"><vig-icon vigChipIcon name="check" /></vig-tag>
      <vig-tag label="Pending" variant="warning" />
      <vig-tag label="Overdue" variant="error" />
      <vig-tag label="New" variant="info" />
      <vig-tag label="Featured" variant="primary" />
      <vig-tag label="Beta" variant="accent" />
      <vig-tag label="Archived" />
    </div>
  `,
})
export class TagSeveritiesDemo {}
```

## Rounded and sizes

`rounded` gives a pill shape instead of the `--radius-chip` corners; `size` is `md` (default) or the denser `sm`.

```typescript title="tag-rounded.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Chip } from '@vigdx/ui/chip';

@Component({
  selector: 'app-tag-rounded',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Chip],
  template: `
    <div class="flex flex-wrap items-center gap-2">
      <vig-tag label="Square corners" variant="info" />
      <vig-tag label="Rounded" variant="info" rounded />
      <vig-tag label="Small" variant="success" size="sm" />
      <vig-tag label="Small rounded" variant="success" size="sm" rounded />
    </div>
  `,
})
export class TagRoundedDemo {}
```

## Removable

`closable` adds a remove button that emits `closed`; remove the item from your state. `closeAriaLabel` names the button, e.g. for translations (the default is the locale's “Remove” plus the label).

```typescript title="tag-removable.ts"
import {
  ChangeDetectionStrategy,
  Component,
  ElementRef,
  Injector,
  afterNextRender,
  inject,
  signal,
  viewChild,
} from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { Chip } from '@vigdx/ui/chip';

const LABELS = ['Urgent', 'Billing', 'Customer'];

@Component({
  selector: 'app-tag-removable',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, Chip],
  template: `
    <div class="flex flex-wrap items-center gap-2">
      <div
        #group
        role="group"
        aria-label="Labels"
        tabindex="-1"
        class="flex flex-wrap items-center gap-2 rounded-chip focus:outline-hidden focus-visible:shadow-(--shadow-focus-ring) forced-colors:focus-visible:outline-[Highlight]"
      >
        @for (label of labels(); track label) {
          <vig-tag
            [label]="label"
            variant="primary"
            closable
            [closeAriaLabel]="'Remove label ' + label"
            (closed)="remove(label)"
          />
        } @empty {
          <span class="text-sm text-muted-foreground">No labels.</span>
        }
      </div>
      <vig-button label="Reset" appearance="text" size="sm" (click)="labels.set(all)" />
    </div>
  `,
})
export class TagRemovableDemo {
  private readonly injector = inject(Injector);
  private readonly group = viewChild.required<ElementRef<HTMLElement>>('group');
  protected readonly all = LABELS;
  protected readonly labels = signal(LABELS);

  protected remove(label: string): void {
    const index = this.labels().indexOf(label);
    this.labels.update((list) => list.filter((item) => item !== label));
    // The removed button takes focus with it: move it to the tag now in its
    // place (or the last one), else to the group, instead of <body>.
    afterNextRender(
      () => {
        const group = this.group().nativeElement;
        const buttons = group.querySelectorAll<HTMLButtonElement>('vig-tag button');
        (buttons[Math.min(index, buttons.length - 1)] ?? group).focus();
      },
      { injector: this.injector },
    );
  }
}
```

## Styling hooks

Internal elements carry a stable `data-part` and the component's `data-scope`; both are public API, so removing one is a breaking change. Select a part by both, e.g. `[data-scope="chip"][data-part="root"] { … }`: the pair stays within this component when kit components nest, and also reaches parts in overlay panels, which render outside the host. State is exposed through `aria-*` and, where listed, a `data-state`; literal values are checked by the API gate, values computed from the component's state follow its documented types. Other `data-*` attributes listed below (such as `data-opening` while an overlay animates) are API too. See [Customizing](https://vigdx.com/docs/theming.md#customizing).

Scope: `[data-scope="chip"]`

| Part | Element | data-state |
| --- | --- | --- |
| `root` | The visible chip box. |   |
| `icon` | Wrapper of the `[vigChipIcon]` slot. |   |
| `label` | The label text. |   |
| `close` | The close (remove) button (`closable`). |   |

## Accessibility

- A tag is plain text: keep the label meaningful without its color. The icon is decorative (`aria-hidden`).
- The remove button is a native `<button>` with a 24px pointer target and a focus ring in the tag's own color; all variants meet WCAG AA text contrast.

## API

### Chip

Selector: `vig-chip, vig-tag` · Kind: component

A compact tag for filters, selections and statuses.

`vig-tag` is an alias selector of the same component, for status tags (PrimeNG `p-tag` territory): `<vig-tag label="Paid" variant="success" />`. Both take the same inputs, so there is one implementation, one set of tokens and one remove button to keep accessible.

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `closable` | `boolean \| undefined` | `undefined` | Adds a close (remove) button that emits `closed`. |
| `closeAriaLabel` | `string \| undefined` | `undefined` | Accessible name of the close button; defaults to `chipRemoveAriaLabel` + label. |
| `dismissible` | `boolean` | `false` | **Deprecated**: Use `closable`; still honored when `closable` is unset. |
| `dismissLabel` | `string \| undefined` | `undefined` | **Deprecated**: Use `closeAriaLabel`; still honored when `closeAriaLabel` is unset. |
| `label` (required) | `string` | — | — |
| `rounded` | `boolean` | `false` | Pill shape (`--radius-chip-pill`) instead of the `--radius-chip` corners. |
| `size` | `ChipSize` | `'md'` | `sm` is the compact tag (11px semibold, ≈20px tall); `md` is the default (12px medium, ≈24px tall). |
| `variant` | `ChipVariant` | `'secondary'` | — |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `closed` | `void` | The close button was activated. The chip does not hide itself. |
| `dismissed` | `void` | **Deprecated**: Use `closed`; emits alongside it. |

### Templates and directives

| Selector | Export | Description |
| --- | --- | --- |
| `[vigChipIcon]` | `ChipIcon` | Marks projected content as the chip's leading icon, e.g. `<vig-icon vigChipIcon name="check" />` or an icon font `<i>`. It sizes with the chip's text (1em) and is hidden from assistive tech: the label carries the meaning. |
