Transfer list
Dual-column shuttle selector for moving permissions or items between Available and Assigned lists with search.
pnpm dlx shadcn@latest add @haze/transfer-list---
import { ArrowLeft, ArrowRight, Search } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Item {
value: string;
label: string;
group?: string;
}
interface Props {
id: string;
name?: string;
availableTitle?: string;
selectedTitle?: string;
items?: Item[];
values?: string[];
searchable?: boolean;
class?: string;
}
const {
id,
name = id,
availableTitle = "Available",
selectedTitle = "Assigned",
items = [
{ value: "projects:read", label: "Read projects" },
{ value: "projects:write", label: "Edit projects" },
{ value: "billing:read", label: "View invoices" },
{ value: "billing:manage", label: "Manage billing" },
{ value: "members:invite", label: "Invite members" },
{ value: "audit:export", label: "Export audit logs" },
],
values = ["projects:read", "projects:write"],
searchable = true,
class: className,
} = Astro.props;
const selectedSet = new Set(values);
const leftItems = items.filter((i) => !selectedSet.has(i.value));
const rightItems = items.filter((i) => selectedSet.has(i.value));
---
<fieldset
id={id}
data-haze-transfer-list
data-name={name}
class={cn("grid min-w-0 gap-3 sm:grid-cols-[minmax(0,1fr)_auto_minmax(0,1fr)] sm:items-stretch", className)}
>
<legend class="sr-only">{availableTitle} and {selectedTitle} transfer selector</legend>
<!-- Available list -->
<div class="flex min-w-0 flex-col overflow-hidden rounded-xl border border-border bg-card">
<div class="flex items-center justify-between border-b border-border bg-muted/40 px-3 py-2">
<span class="text-xs font-semibold text-foreground">{availableTitle}</span>
<span data-tl-count="left" class="font-mono text-xs text-muted-foreground tabular-nums">{leftItems.length}</span>
</div>
{
searchable && (
<label class="flex h-10 items-center gap-2 border-b border-border px-3 text-xs text-muted-foreground transition-[border-color] duration-150 ease-snappy has-[input:focus-visible]:border-ring">
<Search class="size-3.5 shrink-0" aria-hidden="true" />
<input
type="search"
data-tl-search="left"
aria-label={`Filter ${availableTitle}`}
placeholder="Filter…"
class="h-full min-w-0 flex-1 bg-transparent text-xs text-foreground outline-hidden placeholder:text-muted-foreground"
/>
</label>
)
}
<ul aria-label={availableTitle} data-tl-list="left" class="min-h-40 max-h-52 flex-1 divide-y divide-border overflow-y-auto p-1">
{
leftItems.map((item) => (
<li data-tl-item data-value={item.value} data-label={item.label.toLowerCase()}>
<button
type="button"
data-tl-option
aria-pressed="false"
class="flex w-full cursor-pointer items-center rounded-sm px-2.5 py-2 text-left text-[0.8125rem]/5 text-foreground transition-colors duration-75 hover:bg-accent aria-pressed:bg-primary aria-pressed:text-primary-foreground focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
>
<span class="truncate">{item.label}</span>
</button>
</li>
))
}
</ul>
</div>
<!-- Transfer controls -->
<div class="flex items-center justify-center gap-2 sm:flex-col">
<button
type="button"
data-tl-move="right"
aria-label={`Move selected items to ${selectedTitle}`}
class="inline-flex size-10 cursor-pointer items-center justify-center rounded-lg border border-frame bg-field text-foreground transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-frame-strong hover:bg-accent active:scale-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
>
<ArrowRight class="size-4 sm:rotate-0 rotate-90" aria-hidden="true" />
</button>
<button
type="button"
data-tl-move="left"
aria-label={`Move selected items to ${availableTitle}`}
class="inline-flex size-10 cursor-pointer items-center justify-center rounded-lg border border-frame bg-field text-foreground transition-[background-color,border-color,scale] duration-150 ease-snappy hover:border-frame-strong hover:bg-accent active:scale-90 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring"
>
<ArrowLeft class="size-4 sm:rotate-0 rotate-90" aria-hidden="true" />
</button>
</div>
<!-- Selected list -->
<div class="flex min-w-0 flex-col overflow-hidden rounded-xl border border-border bg-card">
<div class="flex items-center justify-between border-b border-border bg-muted/40 px-3 py-2">
<span class="text-xs font-semibold text-foreground">{selectedTitle}</span>
<span data-tl-count="right" class="font-mono text-xs text-muted-foreground tabular-nums">{rightItems.length}</span>
</div>
{
searchable && (
<label class="flex h-10 items-center gap-2 border-b border-border px-3 text-xs text-muted-foreground transition-[border-color] duration-150 ease-snappy has-[input:focus-visible]:border-ring">
<Search class="size-3.5 shrink-0" aria-hidden="true" />
<input
type="search"
data-tl-search="right"
aria-label={`Filter ${selectedTitle}`}
placeholder="Filter…"
class="h-full min-w-0 flex-1 bg-transparent text-xs text-foreground outline-hidden placeholder:text-muted-foreground"
/>
</label>
)
}
<ul aria-label={selectedTitle} data-tl-list="right" class="min-h-40 max-h-52 flex-1 divide-y divide-border overflow-y-auto p-1">
{
rightItems.map((item) => (
<li data-tl-item data-value={item.value} data-label={item.label.toLowerCase()}>
<button
type="button"
data-tl-option
aria-pressed="false"
class="flex w-full cursor-pointer items-center rounded-sm px-2.5 py-2 text-left text-[0.8125rem]/5 text-foreground transition-colors duration-75 hover:bg-accent aria-pressed:bg-primary aria-pressed:text-primary-foreground focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring"
>
<span class="truncate">{item.label}</span>
</button>
</li>
))
}
</ul>
</div>
<div data-tl-hidden-inputs class="hidden">
{rightItems.map((i) => <input type="hidden" name={name} value={i.value} />)}
</div>
<span role="status" data-tl-status class="sr-only"></span>
</fieldset>
<script>
function initTransferLists() {
document.querySelectorAll<HTMLElement>("[data-haze-transfer-list]:not([data-enhanced])").forEach((root) => {
root.setAttribute("data-enhanced", "");
const name = root.dataset.name ?? "transfer";
const leftList = root.querySelector<HTMLElement>('[data-tl-list="left"]');
const rightList = root.querySelector<HTMLElement>('[data-tl-list="right"]');
const leftCount = root.querySelector<HTMLElement>('[data-tl-count="left"]');
const rightCount = root.querySelector<HTMLElement>('[data-tl-count="right"]');
const hiddenBox = root.querySelector<HTMLElement>("[data-tl-hidden-inputs]");
const status = root.querySelector<HTMLElement>("[data-tl-status]");
const syncCountsAndInputs = () => {
if (!leftList || !rightList || !hiddenBox) return;
const leftItems = Array.from(leftList.querySelectorAll<HTMLElement>("[data-tl-item]"));
const rightItems = Array.from(rightList.querySelectorAll<HTMLElement>("[data-tl-item]"));
if (leftCount) leftCount.textContent = String(leftItems.length);
if (rightCount) rightCount.textContent = String(rightItems.length);
hiddenBox.replaceChildren();
rightItems.forEach((item) => {
const input = document.createElement("input");
input.type = "hidden";
input.name = name;
input.value = item.dataset.value ?? "";
hiddenBox.append(input);
});
};
root.addEventListener("click", (ev) => {
const opt = (ev.target as HTMLElement | null)?.closest<HTMLButtonElement>("[data-tl-option]");
if (opt) {
const cur = opt.getAttribute("aria-pressed") === "true";
opt.setAttribute("aria-pressed", String(!cur));
}
});
root.querySelectorAll<HTMLButtonElement>("[data-tl-move]").forEach((btn) => {
btn.addEventListener("click", () => {
const dir = btn.dataset.tlMove;
const src = dir === "right" ? leftList : rightList;
const dst = dir === "right" ? rightList : leftList;
if (!src || !dst) return;
const picked = Array.from(src.querySelectorAll<HTMLElement>('[data-tl-item]:has([aria-pressed="true"])'));
picked.forEach((item) => {
item.querySelector("[data-tl-option]")?.setAttribute("aria-pressed", "false");
item.hidden = false;
dst.append(item);
if (!window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
item.classList.remove("motion-safe:animate-rise");
void item.offsetWidth;
item.classList.add("motion-safe:animate-rise");
}
});
syncCountsAndInputs();
if (status) status.textContent = `Moved ${picked.length} items`;
});
});
(["left", "right"] as const).forEach((side) => {
const searchIn = root.querySelector<HTMLInputElement>(`[data-tl-search="${side}"]`);
const list = side === "left" ? leftList : rightList;
searchIn?.addEventListener("input", () => {
const q = searchIn.value.trim().toLowerCase();
list?.querySelectorAll<HTMLElement>("[data-tl-item]").forEach((item) => {
item.hidden = !!q && !(item.dataset.label ?? "").includes(q);
});
});
});
});
}
initTransferLists();
if (!document.documentElement.hasAttribute("data-haze-transfer-listener")) {
document.documentElement.setAttribute("data-haze-transfer-listener", "");
document.addEventListener("astro:page-load", initTransferLists);
}
</script>When to use
- Assigning fine-grained role capabilities or workspace members
- Selecting and ordering subsets from a larger catalog of options
When not to use
- fewer than 6 simple flags fit better in checkbox-group or multi-select
Installation
Add the Haze registry to components.json once, then install Transfer list with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/transfer-listnpx shadcn@latest add @haze/transfer-listyarn dlx shadcn@latest add @haze/transfer-listbunx --bun shadcn@latest add @haze/transfer-listFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique DOM id for the fieldset. |
| name | string | – | Form submission name for selected hidden inputs. |
| items | Item[] | – | Complete list of selectable items. |
| values | string[] | – | Initially assigned item values. |
| searchable | boolean | true | Shows filter inputs at the top of each column. |
Keyboard interactions
- EnterSpace
- Toggle a focused item before clicking Move.
Accessibility
- Renders two labelled lists of toggle buttons (aria-pressed) with live movement count announcements; Tab reaches each item.
- Synchronizes hidden form inputs on every transfer so native form submission receives assigned values.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Transfer list" with `npx shadcn@latest add @haze/transfer-list`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import TransferList from "@/components/haze/ui/transfer-list.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/transfer-list.md
Customize with real content
Adapt the Haze transfer-list ui for our product. Replace the demo values of these props with our real content: id, name, items, values, searchable. Keep the layout, the heading level rules and these accessibility details: Renders two labelled lists of toggle buttons (aria-pressed) with live movement count announcements; Tab reaches each item. Synchronizes hidden form inputs on every transfer so native form submission receives assigned values. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using transfer-list, check it fits: use it when assigning fine-grained role capabilities or workspace members; selecting and ordering subsets from a larger catalog of options. Avoid it when fewer than 6 simple flags fit better in checkbox-group or multi-select. Alternatives: @haze/multi-select, @haze/checkbox-group, @haze/combobox.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.