# Pick list

Two lists side by side, the available items and the chosen ones, with buttons that move the selected or all shown items between them. In a narrow container the lists stack.

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

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

## Basic

Bind both lists two-way with `[(source)]` and `[(target)]` and name them with `sourceHeading` and `targetHeading`. Moved items are appended to the other list.

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

@Component({
  selector: 'app-pick-list-basic',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [PickList],
  template: `
    <vig-pick-list
      sourceHeading="Available"
      targetHeading="Basket"
      [(source)]="pantry"
      [(target)]="basket"
    />
    <p class="text-sm text-muted-foreground">Basket: {{ basket().join(', ') || 'empty' }}</p>
  `,
})
export class PickListBasicDemo {
  protected readonly pantry = signal(['Bread', 'Butter', 'Cheese', 'Eggs', 'Milk', 'Tomatoes']);
  protected readonly basket = signal(['Coffee']);
}
```

## Filter, reorder, drag and a template

`filter` adds a search field to each list; “Move all” then moves only the matching items. `reorder` adds order buttons to the target, `dragDrop` pointer dragging between and within the lists. `itemLabel` names object items and a `vigListItem` template renders them; `(moved)` reports every transfer, and `[(sourceSelection)]`/`[(targetSelection)]` expose what is selected.

```typescript title="pick-list-reorder.ts"
import { ChangeDetectionStrategy, Component, signal } from '@angular/core';
import { ListItemTemplate } from '@vigdx/ui/listbox';
import { PickList, type PickListMoveEvent } from '@vigdx/ui/pick-list';

interface Person {
  id: number;
  name: string;
  role: string;
}

@Component({
  selector: 'app-pick-list-reorder',
  changeDetection: ChangeDetectionStrategy.OnPush,
  imports: [ListItemTemplate, PickList],
  template: `
    <vig-pick-list
      sourceHeading="Team"
      targetHeading="Reviewers"
      filter
      reorder
      dragDrop
      [(source)]="team"
      [(target)]="reviewers"
      [itemLabel]="name"
      (moved)="log($event)"
    >
      <ng-template vigListItem [vigListItemOf]="team()" let-person>
        <span class="flex min-w-0 flex-col">
          <span class="truncate font-medium">{{ person.name }}</span>
          <span class="truncate text-xs text-muted-foreground">{{ person.role }}</span>
        </span>
      </ng-template>
    </vig-pick-list>
    <p class="text-sm text-muted-foreground">{{ last() }}</p>
  `,
})
export class PickListReorderDemo {
  protected readonly team = signal<Person[]>([
    { id: 1, name: 'Ada Lovelace', role: 'Analyst' },
    { id: 2, name: 'Grace Hopper', role: 'Compiler lead' },
    { id: 3, name: 'Alan Turing', role: 'Research' },
    { id: 4, name: 'Katherine Johnson', role: 'Navigation' },
    { id: 5, name: 'Edsger Dijkstra', role: 'Algorithms' },
  ]);
  protected readonly reviewers = signal<Person[]>([]);
  protected readonly name = (person: Person) => person.name;
  protected readonly last = signal('Nothing moved yet.');

  protected log(event: PickListMoveEvent<Person>): void {
    this.last.set(`${event.items.map((p) => p.name).join(', ')} → ${event.to}`);
  }
}
```

## Related components

Each list is a [listbox](https://vigdx.com/components/listbox.md) in `multiple` mode. For a single list to put in order, use an [order list](https://vigdx.com/components/order-list.md); to pick a few values in a form, a [multi select](https://vigdx.com/components/multi-select.md) or a listbox takes less room.

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

| Part | Element | data-state |
| --- | --- | --- |
| `root` | The `vig-pick-list` host, the container whose width stacks the lists. |   |
| `source` | The source `vig-listbox`; style its `[data-scope="listbox"]` parts. |   |
| `transfer` | The buttons between the lists. |   |
| `move-to-target` | Moves the selected source items to the target. |   |
| `move-all-to-target` | Moves every shown source item to the target. |   |
| `move-to-source` | Moves the selected target items back. |   |
| `move-all-to-source` | Moves every shown target item back. |   |
| `target` | The target `vig-listbox`; style its `[data-scope="listbox"]` parts. |   |
| `controls` | The order buttons of the target (`reorder`). |   |
| `move-top` | The "Move to top" button (`reorder`). |   |
| `move-up` | The "Move up" button (`reorder`). |   |
| `move-down` | The "Move down" button (`reorder`). |   |
| `move-bottom` | The "Move to bottom" button (`reorder`). |   |
| `status` | The visually hidden polite region announcing moves. |   |

## Accessibility

- Both lists are multi-selectable `role="listbox"` elements named by their headings; each has its own tab stop, with the buttons between them.
- The buttons are named after the list they move to, e.g. “Move selected to Basket” and “Move all to Basket” (`labels`), and are disabled while there is nothing to move. When the button you used becomes disabled, focus continues in the list the items came from, or in the other one once it is empty.
- From a list, Alt+ArrowRight moves the selection (or the active item) towards the target and Alt+ArrowLeft back; both are mirrored in right-to-left pages. With `reorder`, Alt+ArrowUp/ArrowDown and Alt+Home/End order the target.
- Every move is announced in a polite live region, e.g. “2 items moved to Basket”.
- The layout follows the container, not the viewport: below 36rem the lists stack and the transfer arrows turn to point down and up. Start and end are logical, so in right-to-left pages the source list is on the right.

## API

### PickList

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

Two lists — the available `source` items and the chosen `target` ones — with buttons moving the selected or all shown items between them. Each list can be filtered (`filter`); `reorder` adds order buttons to the target. Keyboard: select in a list, then Alt+ArrowRight moves the selection towards the target and Alt+ArrowLeft back (mirrored in RTL), Alt+ArrowUp/ArrowDown/Home/End reorder the target; every move is announced. The lists sit side by side and stack in a narrow container.

**Example :**

```html
<vig-pick-list sourceHeading="Available" targetHeading="Chosen"
  [(source)]="available" [(target)]="chosen" [itemLabel]="name" filter />
```

#### Inputs

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `disabled` | `boolean` | `false` | Blocks selecting and moving; the lists stay focusable for reading. |
| `dragDrop` | `boolean` | `false` | Also move items by dragging with a pointer; buttons and keys stay the primary way. |
| `filter` | `boolean` | `false` | A filter field above each list. |
| `itemLabel` | `(item: T) => string` | `(item) => String(item)` | Text of an item, for its accessible name, filtering, typeahead and default rendering. |
| `labels` | `Partial<PickListLabels>` | — | Texts (i18n) over the locale defaults. |
| `reorder` | `boolean` | `false` | Order buttons (and Alt+arrow keys) for the target list. |
| `size` | `FieldSize` | `'md'` | Text size, option padding and button size. |
| `source` (model) | `T[]` | `[]` | The items still available. |
| `sourceHeading` (required) | `string` | — | Visible name of the source list. |
| `sourceSelection` (model) | `T[]` | `[]` | The selected items of the source list, which "move selected" moves. |
| `target` (model) | `T[]` | `[]` | The chosen items, in their order. |
| `targetHeading` (required) | `string` | — | Visible name of the target list. |
| `targetSelection` (model) | `T[]` | `[]` | The selected items of the target list. |

#### Outputs

| Name | Payload | Description |
| --- | --- | --- |
| `moved` | `PickListMoveEvent<T>` | Items moved between the lists, by a button, a key or a drop. |
| `sourceChange` | `T[]` | The items still available. |
| `sourceSelectionChange` | `T[]` | The selected items of the source list, which "move selected" moves. |
| `targetChange` | `T[]` | The chosen items, in their order. |
| `targetSelectionChange` | `T[]` | The selected items of the target list. |

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