# Empty state

Fills a view that has nothing to show yet — no records, no search results, a fresh workspace — with an explanation and the next step to take.

- Package: [@vigdx/ui](https://www.npmjs.com/package/@vigdx/ui)
- Selectors: `vig-empty-state`, `[vigEmptyStateMedia]`, `[vigEmptyStateActions]`
- Source: [libs/ui/src/lib/molecules/empty-state/empty-state.ts](https://github.com/bakyurekk/vigdx/blob/main/libs/ui/src/lib/molecules/empty-state/empty-state.ts)

```typescript title="Import"
import { EmptyState, EmptyStateMedia, EmptyStateActions } from '@vigdx/ui/empty-state';
```

## Basic

`heading` names the section (it replaces the deprecated `title`, which also set the native tooltip); `description` explains why the view is empty and `icon` names a registered icon shown above.

```typescript title="empty-state-basic.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { EmptyState } from '@vigdx/ui/empty-state';

@Component({
  selector: 'app-empty-state-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [EmptyState],
  template: `
    <vig-empty-state
      icon="inbox"
      heading="No messages"
      description="Messages from your team and customers will appear here."
    />
  `,
})
export class EmptyStateBasicDemo {}
```

## Actions

Mark an element `vigEmptyStateActions` to add a centered action row. `class="contents"` lets its buttons join the row's own wrapping flex layout.

```typescript title="empty-state-actions.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Button, ButtonIcon } from '@vigdx/ui/button';
import { EmptyState, EmptyStateActions } from '@vigdx/ui/empty-state';
import { Icon } from '@vigdx/ui/icon';

@Component({
  selector: 'app-empty-state-actions',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, ButtonIcon, EmptyState, EmptyStateActions, Icon],
  template: `
    <vig-empty-state
      icon="file"
      heading="No invoices yet"
      description="Create your first invoice or import existing ones from a CSV file."
    >
      <div vigEmptyStateActions class="contents">
        <vig-button label="Import CSV" variant="secondary">
          <vig-icon vigButtonIcon name="upload" />
        </vig-button>
        <vig-button label="New invoice">
          <vig-icon vigButtonIcon name="plus" />
        </vig-button>
      </div>
    </vig-empty-state>
  `,
})
export class EmptyStateActionsDemo {}
```

## Sizes

`size` scales spacing, icon and type: `sm` for tables, popovers and panels, `md` (default) for cards and sections, `lg` for a whole page.

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

@Component({
  selector: 'app-empty-state-sizes',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [EmptyState],
  template: `
    <div class="grid items-start gap-4 lg:grid-cols-3">
      <vig-empty-state
        class="rounded-card border border-border"
        size="sm"
        icon="search"
        heading="Small"
        description="For table bodies, popovers and side panels."
      />
      <vig-empty-state
        class="rounded-card border border-border"
        icon="search"
        heading="Medium"
        description="The default, for cards and page sections."
      />
      <vig-empty-state
        class="rounded-card border border-border"
        size="lg"
        icon="search"
        heading="Large"
        description="For a whole empty page."
      />
    </div>
  `,
})
export class EmptyStateSizesDemo {}
```

## Custom media

A `vigEmptyStateMedia` element, such as an illustration, replaces the icon. It is tinted with the muted text color, so `currentColor` strokes follow the theme.

```typescript title="empty-state-media.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { EmptyState, EmptyStateActions, EmptyStateMedia } from '@vigdx/ui/empty-state';

@Component({
  selector: 'app-empty-state-media',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, EmptyState, EmptyStateActions, EmptyStateMedia],
  template: `
    <vig-empty-state
      heading="Your board is empty"
      description="Boards collect the tasks of one project. Add a column to get started."
    >
      <svg
        vigEmptyStateMedia
        viewBox="0 0 120 80"
        class="h-20 w-30"
        fill="none"
        stroke="currentColor"
        stroke-width="2"
        aria-hidden="true"
      >
        <rect x="4" y="8" width="32" height="64" rx="4" />
        <rect x="44" y="8" width="32" height="44" rx="4" />
        <rect x="84" y="8" width="32" height="28" rx="4" stroke-dasharray="4 4" />
        <path d="M12 20h16M12 30h12M52 20h16M52 30h10" />
      </svg>
      <div vigEmptyStateActions class="contents">
        <vig-button label="Add column" />
      </div>
    </vig-empty-state>
  `,
})
export class EmptyStateMediaDemo {}
```

## No results

For filters and searches, say that nothing matched and offer a way back. `headingLevel` fits the heading into the surrounding outline, here under the card's heading.

```typescript title="empty-state-no-results.ts"
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { Button } from '@vigdx/ui/button';
import { Card } from '@vigdx/ui/card';
import { EmptyState, EmptyStateActions } from '@vigdx/ui/empty-state';
import { Icon } from '@vigdx/ui/icon';
import { InputField, InputPrefix } from '@vigdx/ui/input-field';

const TEAMS = ['Design', 'Engineering', 'Finance', 'Marketing', 'Support'];

@Component({
  selector: 'app-empty-state-no-results',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Button, Card, EmptyState, EmptyStateActions, Icon, InputField, InputPrefix],
  template: `
    <vig-card heading="Teams" class="max-w-md">
      <vig-input label="Filter teams" type="search" size="sm" [(value)]="query">
        <vig-icon vigInputPrefix name="search" />
      </vig-input>
      <p class="sr-only" role="status">{{ results().length }} teams found</p>
      <div class="mt-3">
        @for (team of results(); track team) {
          <p class="py-1">{{ team }}</p>
        } @empty {
          <vig-empty-state
            size="sm"
            icon="search"
            [headingLevel]="4"
            heading="No matching teams"
            description="Check the spelling or clear the filter."
          >
            <div vigEmptyStateActions class="contents">
              <vig-button
                label="Clear filter"
                variant="secondary"
                size="sm"
                (click)="query.set('')"
              />
            </div>
          </vig-empty-state>
        }
      </div>
    </vig-card>
  `,
})
export class EmptyStateNoResultsDemo {
  protected readonly query = signal('Legal');
  protected readonly results = computed(() => {
    const query = this.query().trim().toLowerCase();
    return TEAMS.filter((team) => team.toLowerCase().includes(query));
  });
}
```

## 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="empty-state"][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="empty-state"]`

| Part | Element | data-state |
| --- | --- | --- |
| `root` | The `<section>`. |   |
| `media` | Wrapper of the `[vigEmptyStateMedia]` slot. |   |
| `icon` | The icon circle. |   |
| `heading` | The `h2`–`h6` heading. |   |
| `description` | The description paragraph. |   |
| `actions` | Wrapper of the `[vigEmptyStateActions]` slot. |   |

## Accessibility

- Renders a `<section>` labelled by its heading, a real `h2`–`h6` heading at `headingLevel` (3 by default). Choose the level that fits the page outline.
- The icon is decorative. Hide custom media from assistive technology with `aria-hidden="true"`, or give a meaningful image an `alt`.
- Actions are the consumer's own buttons and links; label them with what they do, e.g. “New invoice” rather than “Get started”.
- When an empty state replaces results after user input, as with a filter, announce the change, e.g. with a result count in a `role="status"` element.

## API

### EmptyState

Selector: `vig-empty-state` · Kind: component

Placeholder for views with nothing to show yet: a large icon (or a projected `[vigEmptyStateMedia]` illustration), a heading, an optional description and a `[vigEmptyStateActions]` row. Rendered as a `<section>` named by its heading.

**Example :**

```html
<vig-empty-state icon="inbox" heading="No payments yet" description="…">
  <div vigEmptyStateActions><vig-button label="Add payment" /></div>
</vig-empty-state>
```

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `description` | `string \| undefined` | `undefined` | — |
| `heading` | `string \| undefined` | `undefined` | Heading text; also names the section. Set it (or the deprecated `title`). |
| `headingLevel` | `EmptyStateHeadingLevel` | `3` | Heading level (`h2`–`h6`) of the title. |
| `icon` | `string \| undefined` | `undefined` | Registered `vig-icon` name shown large above the title. |
| `size` | `EmptyStateSize` | `'md'` | — |
| `title` | `string \| undefined` | `undefined` | **Deprecated**: Use `heading`; `title` is also the native tooltip attribute. Still honored when `heading` is unset, and never shown as a tooltip. |

### Templates and directives

| Selector | Export | Description |
| --- | --- | --- |
| `[vigEmptyStateMedia]` | `EmptyStateMedia` | Marks projected content (illustration, image) as the empty state's media. |
| `[vigEmptyStateActions]` | `EmptyStateActions` | Marks projected content as the empty state's action row. |
