# Breadcrumb

A trail of links from the top of a hierarchy to the current page. Use it on pages nested two or more levels deep, so users can see where they are and step back up.

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

```typescript title="Import"
import { Breadcrumb } from '@vigdx/ui/breadcrumb';
```

## Basic

Pass the trail as `items`, from the root to the current page. Items with an `href` render as links, `icon` adds a registered icon such as `home`, and the last item is always the current page.

```typescript title="breadcrumb-basic.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Breadcrumb, type BreadcrumbItem } from '@vigdx/ui/breadcrumb';

@Component({
  selector: 'app-breadcrumb-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Breadcrumb],
  template: `<vig-breadcrumb [items]="items" />`,
})
export class BreadcrumbBasicDemo {
  protected readonly items: BreadcrumbItem[] = [
    { label: 'Home', href: '/', icon: 'home' },
    { label: 'Components', href: '/components' },
    { label: 'Breadcrumb' },
  ];
}
```

## Collapsed

`maxItems` keeps the first item and the last `maxItems - 1`, hiding the middle behind an ellipsis button that reveals the full trail. `separator` takes any registered icon name.

```typescript title="breadcrumb-collapsed.ts"
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Breadcrumb, type BreadcrumbItem } from '@vigdx/ui/breadcrumb';

@Component({
  selector: 'app-breadcrumb-collapsed',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Breadcrumb],
  template: `
    <vig-breadcrumb ariaLabel="Folder path" [items]="items" [maxItems]="3" />
    <vig-breadcrumb ariaLabel="Folder path, full" [items]="items" separator="chevrons-right" />
  `,
})
export class BreadcrumbCollapsedDemo {
  protected readonly items: BreadcrumbItem[] = [
    { label: 'Drive', href: '#drive', icon: 'home' },
    { label: 'Projects', href: '#projects' },
    { label: '2026', href: '#2026' },
    { label: 'Marketing', href: '#marketing' },
    { label: 'Spring campaign', href: '#spring' },
    { label: 'Brief.pdf', icon: 'file' },
  ];
}
```

## Item click

Items without an `href` render as buttons; handle `itemClick` to navigate in code, e.g. with the router or in a master–detail view. `disabled` items show as plain text.

```typescript title="breadcrumb-item-click.ts"
import { ChangeDetectionStrategy, Component, computed, signal } from '@angular/core';
import { Breadcrumb, type BreadcrumbItem } from '@vigdx/ui/breadcrumb';
import { Button } from '@vigdx/ui/button';

const FULL_PATH = ['Dashboard', 'Payments', 'Archive', 'Invoice 104'];

@Component({
  selector: 'app-breadcrumb-item-click',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [Breadcrumb, Button],
  template: `
    <vig-breadcrumb ariaLabel="Payment folders" [items]="items()" (itemClick)="open($event)" />
    <div class="flex flex-wrap items-center gap-3">
      <span class="text-sm text-muted-foreground">Viewing: {{ current() }}</span>
      <vig-button
        label="Reset"
        variant="secondary"
        appearance="text"
        size="sm"
        (click)="path.set(fullPath)"
      />
    </div>
  `,
})
export class BreadcrumbItemClickDemo {
  protected readonly fullPath = FULL_PATH;
  protected readonly path = signal(FULL_PATH);
  protected readonly current = computed(() => this.path()[this.path().length - 1]);

  // Items without an href render as buttons; "Archive" is shown but not navigable.
  protected readonly items = computed<BreadcrumbItem[]>(() =>
    this.path().map((label, index) => ({
      label,
      icon: index === 0 ? 'home' : undefined,
      disabled: label === 'Archive',
    })),
  );

  protected open(item: BreadcrumbItem): void {
    this.path.update((path) => path.slice(0, path.indexOf(item.label) + 1));
  }
}
```

## 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="breadcrumb"][data-part="list"] { … }`: 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="breadcrumb"]`

| Part | Element | data-state |
| --- | --- | --- |
| `list` | The `<ol>`. |   |
| `item` | One `<li>`. |   |
| `separator` | The separator icon. |   |
| `link` | A crumb: link, button or text. | `current, disabled` |
| `expand` | The button that shows collapsed crumbs (`maxItems`). |   |

## Accessibility

- Follows the WAI-ARIA APG breadcrumb pattern: a `<nav>` landmark around an ordered list. Its name defaults to the localized “Breadcrumb”; override it with `ariaLabel` when a page holds more than one trail.
- The last item carries `aria-current="page"`, so it is announced as the current page. With an `href` it stays a link, keeping the trail one consistent list of links; without one it is plain text. In forced-colors mode it is underlined, since its bolder weight is the only other cue.
- Separators and icons are decorative and hidden from assistive technology; the separator mirrors in right-to-left layouts.
- The ellipsis is a button named by `expandAriaLabel`. Activating it reveals the hidden items and moves focus to the first of them.

## API

### Breadcrumb

Selector: `vig-breadcrumb` · Kind: component

Trail of links to the current page: `<nav><ol><li>`, the last item marked `aria-current="page"` — still a link when it has an `href`, plain text otherwise. With `maxItems` the middle collapses into an ellipsis button that reveals the full trail.

**Example :**

```html
<vig-breadcrumb [items]="[{ label: 'Home', href: '/' }, { label: 'Parks' }]" />
```

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `ariaLabel` | `string \| undefined` | `undefined` | — |
| `expandAriaLabel` | `string \| undefined` | `undefined` | — |
| `items` | `readonly BreadcrumbItem[]` | `[]` | — |
| `maxItems` | `number \| undefined` | `undefined` | Collapses the middle of longer trails into an ellipsis (minimum 2). |
| `separator` | `string` | `'chevron-right'` | Registered `vig-icon` name between items; mirrored in RTL. |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `itemClick` | `BreadcrumbItem` | Activation of any interactive item: a link (the current page's too) or a button. |
