# Order list

Puts the items of one list in order. Select items, then move them with the buttons beside the list or with Alt and the arrow keys; every move is announced.

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

```typescript title="Import"
import { OrderList } from '@vigdx/ui/order-list';
import { ListItemTemplate } from '@vigdx/ui/listbox';
```

## Basic

Bind the items with `[(value)]`: each move writes a new array. `heading` names the list. The buttons move the selected items one step or to the top or bottom, keeping their relative order.

```typescript title="order-list-basic.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { OrderList } from '@vigdx/ui/order-list';

@Component({
  selector: 'app-order-list-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [OrderList],
  template: `
    <vig-order-list class="max-w-md" heading="Priorities" [(value)]="priorities" />
    <p class="text-sm text-muted-foreground">Order: {{ priorities().join(' → ') }}</p>
  `,
})
export class OrderListBasicDemo {
  protected readonly priorities = signal([
    'Security review',
    'Release notes',
    'Docs update',
    'Performance pass',
    'Design QA',
  ]);
}
```

## Any item type, a template and dragging

Items can be objects: `itemLabel` names each one (accessible name, typeahead, announcements) and a `vigListItem` template renders it, typed by `vigListItemOf`. `[(selection)]` exposes the selected items and `(reordered)` reports each move. `dragDrop` adds pointer dragging on top of the buttons and keys; from 500 items the list is virtualized and does not drag (a dev-mode warning says so).

```typescript title="order-list-template.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { ListItemTemplate } from '@vigdx/ui/listbox';
import { OrderList } from '@vigdx/ui/order-list';

interface Song {
  id: number;
  title: string;
  artist: string;
}

@Component({
  selector: 'app-order-list-template',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [ListItemTemplate, OrderList],
  template: `
    <vig-order-list
      class="max-w-md"
      heading="Playlist"
      dragDrop
      [(value)]="songs"
      [(selection)]="selected"
      [itemLabel]="title"
    >
      <ng-template vigListItem [vigListItemOf]="songs()" let-song>
        <span class="flex min-w-0 flex-col">
          <span class="truncate font-medium">{{ song.title }}</span>
          <span class="truncate text-xs text-muted-foreground">{{ song.artist }}</span>
        </span>
      </ng-template>
    </vig-order-list>
    <p class="text-sm text-muted-foreground">{{ selected().length }} selected</p>
  `,
})
export class OrderListTemplateDemo {
  protected readonly songs = signal<Song[]>([
    { id: 1, title: 'Blue in Green', artist: 'Miles Davis' },
    { id: 2, title: 'Naima', artist: 'John Coltrane' },
    { id: 3, title: 'Peace Piece', artist: 'Bill Evans' },
    { id: 4, title: 'Footprints', artist: 'Wayne Shorter' },
  ]);
  protected readonly selected = signal<Song[]>([]);
  protected readonly title = (song: Song) => song.title;
}
```

## Related components

The list is a [listbox](https://vigdx.com/components/listbox.md) in `multiple` mode, so it is selected and browsed the same way. To choose items from one list into another, use a [pick list](https://vigdx.com/components/pick-list.md).

## 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="order-list"][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="order-list"]`

| Part | Element | data-state |
| --- | --- | --- |
| `root` | The `vig-order-list` host. |   |
| `controls` | The column of move buttons. |   |
| `move-top` | The "Move to top" `vig-button`. |   |
| `move-up` | The "Move up" `vig-button`. |   |
| `move-down` | The "Move down" `vig-button`. |   |
| `move-bottom` | The "Move to bottom" `vig-button`. |   |
| `list` | The `vig-listbox`; style its own `[data-scope="listbox"]` parts. |   |
| `status` | The visually hidden polite region announcing moves. |   |

## Accessibility

- The list is a multi-selectable `role="listbox"` named by `heading`: click, Space, Shift+arrows and Ctrl/Cmd+A select.
- The move buttons are named “Move to top”, “Move up”, “Move down” and “Move to bottom” (`labels`) and are disabled while the selection cannot move that way. When the button you used becomes disabled, focus continues in the list.
- From the list, Alt+ArrowUp and Alt+ArrowDown move the selection one step, Alt+Home and Alt+End to the top and bottom (Option on macOS); with nothing selected they move the active item.
- Each move is announced in a polite live region, e.g. “Release notes moved to position 3 of 5” (`labels.reorderedAnnouncement`).
- Dragging is an extra for pointer users; the buttons and keys stay the way to reorder. A virtualized list (from 500 items) does not drag.

## API

### OrderList

Selector: `vig-order-list` · Kind: component

Reorders one list. Select items (Space, Shift+arrows, Ctrl/Cmd+A, click) and move them with the buttons beside the list or Alt+ArrowUp/ArrowDown (one step) and Alt+Home/End (to the top or bottom); with nothing selected the keys move the active item. Each move is announced politely. `dragDrop` adds pointer dragging on top. `value` is the ordered array: bind it two-way.

**Example :**

```html
<vig-order-list heading="Playlist" [(value)]="songs" [itemLabel]="songTitle" />
```

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `disabled` | `boolean` | `false` | Blocks selecting and moving; the lists stay focusable for reading. |
| `dragDrop` | `boolean` | `false` | Also reorder by dragging with a pointer; the buttons and keys stay the primary way. |
| `heading` (required) | `string` | — | Visible name of the list. |
| `itemLabel` | `(item: T) => string` | `(item) => String(item)` | Text of an item, for its accessible name, typeahead and default rendering. |
| `labels` | `Partial<OrderListLabels>` | — | Texts (i18n) over the locale defaults. |
| `selection` (model) | `T[]` | `[]` | The selected items, which the buttons and Alt+keys move. |
| `size` | `FieldSize` | `'md'` | Text size, option padding and button size. |
| `value` (model) | `T[]` | `[]` | The items in their order; every move writes a new array. |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `reordered` | `OrderListReorderEvent<T>` | Items moved by a button, a key or a drop; `valueChange` carries the whole order. |
| `selectionChange` | `T[]` | The selected items, which the buttons and Alt+keys move. |
| `valueChange` | `T[]` | The items in their order; every move writes a new array. |

### ListItemTemplate

Selector: `ng-template[vigListItem]` · Kind: directive

Custom rendering for the items of `vig-order-list` and `vig-pick-list`, replacing the default label. Bind the same items to `vigListItemOf` (like `ngForOf`) to type `let-item`; without it the item is `unknown`.

**Example :**

```html
<vig-order-list heading="Tasks" [(value)]="tasks" [itemLabel]="taskLabel">
  <ng-template vigListItem [vigListItemOf]="tasks" let-task>
    <span class="truncate">{{ task.title }}</span>
    <vig-tag class="ms-auto" [value]="task.status" />
  </ng-template>
</vig-order-list>
```

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `vigListItemOf` | `readonly T[] \| null \| undefined` | `undefined` | Type-only: the items the template renders, so the template type checker infers the item type. Not read at runtime. |
