# Chip

A compact tag for applied filters, selected values, keywords and statuses (`vig-tag` is the same component under a second selector). Make it closable when the user can remove what it stands for; use a badge for counts and status dots.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-chip`, `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';
```

## Variants

`variant` picks a soft tone: `secondary` (default), `primary`, `accent`, `ghost` and the four status colors.

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

@Component({
  selector: 'app-chip-variants',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Chip],
  template: `
    <div class="flex flex-wrap items-center gap-2">
      <vig-chip label="Secondary" />
      <vig-chip label="Primary" variant="primary" />
      <vig-chip label="Accent" variant="accent" />
      <vig-chip label="Ghost" variant="ghost" />
      <vig-chip label="Info" variant="info" />
      <vig-chip label="Success" variant="success" />
      <vig-chip label="Warning" variant="warning" />
      <vig-chip label="Error" variant="error" />
    </div>
  `,
})
export class ChipVariantsDemo {}
```

## Sizes

`size` is `md` (default, about 24px tall) or `sm`, a denser tag for tables and toolbars.

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

@Component({
  selector: 'app-chip-sizes',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Chip],
  template: `
    <div class="flex flex-wrap items-center gap-2">
      <vig-chip label="Small" size="sm" variant="primary" />
      <vig-chip label="Medium" variant="primary" />
      <vig-chip label="Small" size="sm" [closable]="true" />
      <vig-chip label="Medium" [closable]="true" />
    </div>
  `,
})
export class ChipSizesDemo {}
```

## Closable

`closable` adds a remove button that emits `closed` (formerly `dismissible` and `dismissed`). The chip does not hide itself: remove the item from your state, as in this filter bar.

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

const FILTERS = ['Status: Open', 'Assignee: Me', 'Label: Bug', 'Updated: Last 7 days'];

@Component({
  selector: 'app-chip-closable',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, Chip],
  template: `
    <div class="flex flex-wrap items-center gap-2">
      @for (filter of filters(); track filter) {
        <vig-chip [label]="filter" variant="primary" [closable]="true" (closed)="remove(filter)" />
      } @empty {
        <span class="text-sm text-muted-foreground">No filters applied.</span>
      }
      <vig-button label="Reset filters" appearance="text" size="sm" (click)="reset()" />
    </div>
  `,
})
export class ChipClosableDemo {
  protected readonly filters = signal(FILTERS);

  protected remove(filter: string): void {
    this.filters.update((list) => list.filter((item) => item !== filter));
  }

  protected reset(): void {
    this.filters.set(FILTERS);
  }
}
```

## Labels and truncation

`closeAriaLabel` replaces the remove button's accessible name, e.g. for translations. Long labels truncate to the available width and show the full text as a tooltip.

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

@Component({
  selector: 'app-chip-labels',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Chip],
  template: `
    <div class="flex flex-wrap items-center gap-2">
      <vig-chip label="Berlin" [closable]="true" closeAriaLabel="Berlin entfernen" />
      <vig-chip label="München" [closable]="true" closeAriaLabel="München entfernen" />
      <div class="w-40">
        <vig-chip label="Customer success and support operations" variant="info" />
      </div>
    </div>
  `,
})
export class ChipLabelsDemo {}
```

## 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

- The chip itself is plain text; only the remove button is focusable. It is a native `<button>`, activated with Enter or Space, with a 24px pointer target around its smaller icon (WCAG 2.5.8).
- The remove button is named “Remove” plus the label by default (`chipRemoveAriaLabel`); override it per chip with `closeAriaLabel`.
- After a chip is removed its button disappears: move focus somewhere sensible, such as the next chip or the filter input, when users remove chips with the keyboard.
- Focus shows a ring in the chip's own color; all tones meet WCAG AA contrast for their text.

## 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. |
