# Swipe actions

> A list whose rows slide sideways to reveal leading and trailing actions, with a full-swipe shortcut, a More actions menu and undo.

- Kind: ui · Category: Actions · Interactivity: script
- Install: `npx shadcn@latest add @haze/swipe-actions`
- File: `src/components/haze/ui/swipe-actions.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/button, @haze/utils
- Docs page: https://hazeui.com/ui/swipe-actions

## Use when
- An inbox or task list on touch screens needs quick archive, snooze or mark-read actions on each row.
- A destructive shortcut should need a deliberate long swipe, with Undo as the safety net.

## Avoid when
- Use dropdown-menu for one set of actions that belongs to a single trigger, not to every row of a list.
- Use sortable-list when the gesture should reorder items rather than reveal actions.

## Alternatives
- [dropdown-menu](https://hazeui.com/ui/dropdown-menu.md)
- [sortable-list](https://hazeui.com/ui/sortable-list.md)
- [card-stack](https://hazeui.com/ui/card-stack.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Unique caller supplied prefix for the control and its associated content. |
| name | `string` | id-action | no | Fallback submit button name; each value combines row and action identifiers. |
| label | `string` | Team inbox | no | Accessible name for the row list. |
| items | `{ id: string; label: string; description?: string }[]` | Three demo inbox rows | no | Rows with stable identifiers and concise readable content. |
| leading | `{ id: string; label: string; tone?: "neutral" \| "accent" \| "danger"; keepRow?: boolean; icon?: "archive" \| "mail-open" \| "clock" \| "trash" }[]` | Mark read (accent, keepRow) | no | Actions revealed under the left edge by swiping right; the first one is the full-swipe action. keepRow springs the row back instead of removing it. |
| trailing | `{ id: string; label: string; tone?: "neutral" \| "accent" \| "danger"; keepRow?: boolean; icon?: "archive" \| "mail-open" \| "clock" \| "trash" }[]` | Snooze (neutral, keepRow) / Archive (accent, removes the row) | no | Actions revealed under the right edge by swiping left; the last one is the full-swipe action. |
| class | `string` |  | no | Additional classes on this component's outer wrapper. |

## Accessibility
- The gesture is a shortcut only: revealed action buttons are aria-hidden and out of the tab order, and every row has a visible More actions button with the same actions.
- The More actions menu is a native popover: Enter or Space opens it, Arrow keys, Home and End move between actions, Escape closes it and returns focus to the button.
- Horizontal intent is locked after about 6 px before pointer capture, so vertical touch movement keeps scrolling the page; text selection is blocked while dragging.
- Only one row stays open. A press outside the row or Escape closes it; reduced motion jumps to the stops and fades removed rows instead of animating height.
- After a removing action, focus moves to the next row's More actions button, or to Undo when no rows remain; a status region names the affected row.
- Without script the menu buttons submit row:action through the enclosing form; enhanced consumers listen for the cancelable haze:swipe-action event, and Undo emits haze:swipe-undo.
- Key Enter / Space on More actions: Open the row's action menu and focus its first action.
- Key Arrow Up / Arrow Down / Home / End: Move between actions in the open menu.
- Key Escape: Close the menu and return focus to More actions, or close an open swiped row.

## Agent prompts

### Install and use

Install the Haze UI component "Swipe actions" with `npx shadcn@latest add @haze/swipe-actions`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/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 SwipeActions from "@/components/haze/ui/swipe-actions.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: https://hazeui.com/ui/swipe-actions.md

### Customize with real content

Adapt the Haze swipe-actions ui for our product. Replace the demo values of these props with our real content: id, name, label, items, leading, trailing, class. Keep the layout, the heading level rules and these accessibility details: The gesture is a shortcut only: revealed action buttons are aria-hidden and out of the tab order, and every row has a visible More actions button with the same actions. The More actions menu is a native popover: Enter or Space opens it, Arrow keys, Home and End move between actions, Escape closes it and returns focus to the button. Horizontal intent is locked after about 6 px before pointer capture, so vertical touch movement keeps scrolling the page; text selection is blocked while dragging. Only one row stays open. A press outside the row or Escape closes it; reduced motion jumps to the stops and fades removed rows instead of animating height. After a removing action, focus moves to the next row's More actions button, or to Undo when no rows remain; a status region names the affected row. Without script the menu buttons submit row:action through the enclosing form; enhanced consumers listen for the cancelable haze:swipe-action event, and Undo emits haze:swipe-undo. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using swipe-actions, check it fits: use it when an inbox or task list on touch screens needs quick archive, snooze or mark-read actions on each row.; a destructive shortcut should need a deliberate long swipe, with undo as the safety net.. Avoid it when use dropdown-menu for one set of actions that belongs to a single trigger, not to every row of a list.; use sortable-list when the gesture should reorder items rather than reveal actions.. Alternatives: @haze/dropdown-menu, @haze/sortable-list, @haze/card-stack.

## Example requests that should lead here
- Add a swipe-to-reveal inbox list: swipe right to mark read, swipe left for Snooze and Archive, with Undo
- Make each task row swipeable with a trash action that a full swipe commits, plus a More actions menu for keyboard users

## Source

```astro
---
import { Archive, Clock, Ellipsis, MailOpen, Trash2 } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import Button from "./button.astro";

interface Row { id: string; label: string; description?: string; }
interface Action {
  id: string;
  label: string;
  tone?: "neutral" | "accent" | "danger";
  /** The row stays after the action and springs back home. Without it the row leaves the list. */
  keepRow?: boolean;
  icon?: "archive" | "mail-open" | "clock" | "trash";
}
interface Props {
  /** Unique on the page. Names each row's menu and its anchor. */
  id: string;
  name?: string;
  label?: string;
  items?: Row[];
  /** Revealed by swiping right. The first one is the full-swipe action. */
  leading?: Action[];
  /** Revealed by swiping left. The last one is the full-swipe action. */
  trailing?: Action[];
  class?: string;
}
const {
  id,
  name = `${id}-action`,
  label = "Team inbox",
  items = [
    { id: "review", label: "Review request", description: "Mina shared the release checklist." },
    { id: "meeting", label: "Planning notes", description: "Three decisions are ready to review." },
    { id: "summary", label: "Weekly summary", description: "Your workspace activity is ready." },
  ],
  leading = [{ id: "read", label: "Mark read", tone: "accent", keepRow: true, icon: "mail-open" }],
  trailing = [
    { id: "snooze", label: "Snooze", tone: "neutral", keepRow: true, icon: "clock" },
    { id: "archive", label: "Archive", tone: "accent", icon: "archive" },
  ],
  class: className,
} = Astro.props;

const icons = { archive: Archive, "mail-open": MailOpen, clock: Clock, trash: Trash2 };
const tones = {
  neutral: "bg-muted text-foreground",
  accent: "bg-accent text-foreground",
  danger: "bg-accent text-destructive",
};
const all = [...leading, ...trailing];
// Each slot is 5rem wide; a group's resting width is its slot count.
const sides = [
  { key: "leading", actions: leading, outer: 0, edge: "left-0" },
  { key: "trailing", actions: trailing, outer: trailing.length - 1, edge: "right-0" },
].filter((side) => side.actions.length > 0);
const menuItem = "flex min-h-9 w-full cursor-pointer items-center gap-2 rounded-sm px-3 py-1.5 text-left text-[0.8125rem]/5 transition-colors duration-75 focus-visible:outline-2 focus-visible:-outline-offset-2 focus-visible:outline-ring [&_svg]:size-4 [&_svg]:shrink-0";
---
<div data-haze-swipe-actions class={cn("grid w-full min-w-0 gap-3", className)}>
  <ul aria-label={label} class="-my-1 min-w-0">
    {items.map((item) => {
      const menuId = `${id}-${item.id}-menu`;
      return (
        <li data-swipe-row data-row-id={item.id} data-label={item.label} style="--reveal:0px" class="group/row min-w-0 overflow-hidden py-1 transition-[height,padding,opacity] duration-300 ease-snappy motion-reduce:transition-none">
          <div data-row-shell class="relative overflow-hidden rounded-xl border border-border bg-card text-card-foreground">
            {sides.map((side) => (
              <div data-underlay={side.key} data-slots={side.actions.length} class={cn("invisible absolute inset-y-0 flex w-(--reveal) overflow-hidden transition-[width] duration-200 ease-snappy group-data-[dragging]/row:transition-none motion-reduce:transition-none", side.edge, side.key === "leading" ? "group-data-[side=leading]/row:visible" : "group-data-[side=trailing]/row:visible")}>
                {side.actions.map((action, index) => {
                  const Icon = icons[action.icon ?? "archive"];
                  const outer = index === side.outer;
                  return (
                    <button
                      type="button"
                      tabindex="-1"
                      aria-hidden="true"
                      data-row-action={action.id}
                      data-label={action.label}
                      data-keep={action.keepRow ? "true" : undefined}
                      data-outer={outer ? "true" : undefined}
                      class={cn(
                        "@container flex min-w-0 grow basis-0 cursor-pointer flex-col items-center justify-center gap-1 overflow-hidden text-[0.6875rem]/4 font-medium select-none transition-[flex-grow] duration-200 ease-snappy motion-reduce:transition-none [&_svg]:size-4 [&_svg]:shrink-0",
                        tones[action.tone ?? "neutral"],
                        !outer && "group-data-[armed]/row:grow-0",
                      )}
                    >
                      <Icon aria-hidden="true" class="scale-75 opacity-0 transition-[opacity,scale] duration-150 ease-snappy motion-reduce:transition-none @min-[32px]:scale-100 @min-[32px]:opacity-100" />
                      <span class="whitespace-nowrap opacity-0 transition-opacity duration-150 ease-snappy motion-reduce:transition-none @min-[56px]:opacity-100">{action.label}</span>
                    </button>
                  );
                })}
              </div>
            ))}
            <div data-row-content class="relative flex touch-pan-y items-start gap-2 bg-card p-4.5 pe-2.5 transition-[translate] duration-200 ease-snappy motion-reduce:transition-none group-data-[dragging]/row:cursor-grabbing group-data-[dragging]/row:transition-none group-data-[dragging]/row:select-none">
              <div class="grid min-w-0 flex-1 gap-1">
                <p class="text-[0.8125rem]/5 font-medium">{item.label}</p>
                {item.description && <p class="text-[0.8125rem]/5 text-muted-foreground">{item.description}</p>}
                <span data-row-state hidden class="text-[0.8125rem]/5 text-muted-foreground" />
              </div>
              <Button variant="ghost" size="icon" popovertarget={menuId} aria-label={`More actions for ${item.label}`} data-row-more style={`anchor-name: --${menuId}`} class="-my-1.5 size-8">
                <Ellipsis aria-hidden="true" />
              </Button>
            </div>
          </div>
          <div
            popover
            id={menuId}
            data-row-menu
            aria-label={`Actions for ${item.label}`}
            style={`position-anchor: --${menuId}`}
            class="m-auto max-h-[min(24rem,calc(100dvh-2rem))] w-48 max-w-[calc(100vw-1rem)] origin-top-right -translate-y-1.5 scale-[0.97] overflow-y-auto rounded-lg border border-border bg-popover p-1 text-[0.8125rem] text-popover-foreground opacity-0 shadow-float backdrop:bg-background/60 transition-[opacity,scale,translate,overlay,display] transition-discrete duration-150 ease-snappy open:translate-y-0 open:scale-100 open:opacity-100 starting:open:-translate-y-1.5 starting:open:scale-[0.97] starting:open:opacity-0 supports-[position-area:block-end]:mx-0 supports-[position-area:block-end]:my-1.5 supports-[position-area:block-end]:ms-2 supports-[position-area:block-end]:backdrop:bg-transparent supports-[position-area:block-end]:[position-area:block-end_span-inline-start] supports-[position-area:block-end]:[position-try-fallbacks:flip-block,flip-inline,flip-block_flip-inline]"
          >
            <ul role="list" class="grid gap-0.5">
              {all.map((action) => {
                const Icon = icons[action.icon ?? "archive"];
                return (
                  <li>
                    <button
                      type="submit"
                      name={name}
                      value={`${item.id}:${action.id}`}
                      data-row-action={action.id}
                      data-label={action.label}
                      data-keep={action.keepRow ? "true" : undefined}
                      class={cn(menuItem, action.tone === "danger" ? "text-destructive hover:bg-destructive/8 focus-visible:bg-destructive/8" : "text-popover-foreground hover:bg-accent focus-visible:bg-accent [&_svg]:text-muted-foreground")}
                    >
                      <Icon aria-hidden="true" />
                      <span class="min-w-0 flex-1 truncate">{action.label}</span>
                    </button>
                  </li>
                );
              })}
            </ul>
          </div>
        </li>
      );
    })}
  </ul>
  <div class="flex min-h-8 flex-wrap items-center justify-between gap-2"><p data-swipe-status role="status" class="text-[0.8125rem]/5 text-muted-foreground">Swipe a row sideways or use its More actions button.</p><button type="button" data-swipe-undo hidden class="min-h-8 cursor-pointer rounded-lg px-2 text-[0.8125rem]/5 font-medium text-foreground transition-[background-color,scale] duration-150 ease-snappy hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring active:scale-[0.97] active:duration-75">Undo</button></div>
</div>
<script>
  interface Ctl { el: HTMLElement; close: () => void; }
  let openCtl: Ctl | null = null;
  const reduced = () => matchMedia("(prefers-reduced-motion: reduce)").matches;

  function enhance(root: HTMLElement) {
    if (root.hasAttribute("data-enhanced")) return;
    const rows = Array.from(root.querySelectorAll<HTMLElement>("[data-swipe-row]"));
    const status = root.querySelector<HTMLElement>("[data-swipe-status]");
    const undo = root.querySelector<HTMLButtonElement>("[data-swipe-undo]");
    if (!status || !undo) return;
    let previous: { row: HTMLElement; state: string } | null = null;
    const ctls = new Map<HTMLElement, { restore: () => void }>();
    const more = (row: HTMLElement) => row.querySelector<HTMLElement>("[data-row-more]");

    const focusNeighbour = (row: HTMLElement) => {
      const i = rows.indexOf(row);
      const next = [...rows.slice(i + 1), ...rows.slice(0, i).reverse()].find((item) => !item.hidden);
      if (next) more(next)?.focus(); else undo.focus();
    };

    // Returns false when a listener cancelled the action.
    const run = (row: HTMLElement, action: string, label: string, remove: boolean) => {
      const event = new CustomEvent("haze:swipe-action", { bubbles: true, cancelable: true, detail: { id: row.dataset.rowId, action } });
      if (!root.dispatchEvent(event)) return false;
      const state = row.querySelector<HTMLElement>("[data-row-state]")!;
      previous = { row, state: state.textContent || "" };
      undo.hidden = false;
      if (!remove) { state.textContent = label; state.hidden = false; }
      status.textContent = `${label}: ${row.dataset.label}.`;
      return true;
    };

    rows.forEach((row) => {
      const shell = row.querySelector<HTMLElement>("[data-row-shell]")!;
      const content = row.querySelector<HTMLElement>("[data-row-content]")!;
      const menu = row.querySelector<HTMLElement>("[data-row-menu]")!;
      const lead = row.querySelector<HTMLElement>('[data-underlay="leading"]');
      const trail = row.querySelector<HTMLElement>('[data-underlay="trailing"]');
      const groupFor = (side: number) => (side > 0 ? lead : trail);
      // Each slot is 5rem wide.
      const rest = (side: number) => { const g = groupFor(side); return g ? Number(g.dataset.slots) * 5 * parseFloat(getComputedStyle(document.documentElement).fontSize) : 0; };
      const actionOf = (side: number) => groupFor(side)?.querySelector<HTMLButtonElement>("[data-outer]") ?? null;
      let x = 0, timer = 0;
      let drag: { id: number; sx: number; sy: number; start: number; locked: boolean; raw: number; samples: { t: number; x: number }[] } | null = null;

      // --reveal is the exposed distance; the active side's underlay is exactly that wide.
      const setReveal = (px: number) => row.style.setProperty("--reveal", `${px}px`);
      const setX = (value: number) => { x = value; content.style.translate = `${value}px 0`; };
      // Back at rest or at an open stop: hide an unused side.
      const finish = () => {
        const side = Math.sign(x);
        setReveal(Math.abs(x));
        if (x === 0) row.removeAttribute("data-side"); else row.setAttribute("data-side", side > 0 ? "leading" : "trailing");
        row.removeAttribute("data-armed");
      };
      const ctl: Ctl = { el: row, close: () => settle(0) };
      const settle = (target: number) => {
        window.clearTimeout(timer);
        const side = Math.sign(target) || Math.sign(x);
        if (side) row.setAttribute("data-side", side > 0 ? "leading" : "trailing");
        setReveal(Math.abs(target));
        row.removeAttribute("data-armed");
        setX(target);
        if (target === 0) { if (openCtl?.el === row) openCtl = null; } else openCtl = ctl;
        if (reduced()) finish(); else timer = window.setTimeout(finish, 230);
      };

      const measureX = () => content.getBoundingClientRect().left - shell.getBoundingClientRect().left - shell.clientLeft;
      const resist = (raw: number) => {
        const side = Math.sign(raw), stop = rest(side), over = Math.abs(raw) - stop;
        if (!stop) return side * Math.min(Math.abs(raw) * 0.2, 28);
        return over <= 0 ? raw : side * (stop + over * 0.55);
      };

      row.addEventListener("selectstart", (event) => { if (drag) event.preventDefault(); });
      row.addEventListener("pointerdown", (event) => {
        if (!event.isPrimary || (event.pointerType === "mouse" && event.button !== 0)) return;
        const target = event.target as Element;
        if (target.closest("button,a,input,[popover]") || !content.contains(target)) return;
        if (openCtl && openCtl.el !== row) openCtl.close();
        window.clearTimeout(timer);
        const start = Math.round(measureX());
        x = start;
        drag = { id: event.pointerId, sx: event.clientX, sy: event.clientY, start, locked: false, raw: start, samples: [] };
      });
      row.addEventListener("pointermove", (event) => {
        if (!drag || drag.id !== event.pointerId) return;
        const dx = event.clientX - drag.sx, dy = event.clientY - drag.sy;
        if (!drag.locked) {
          if (Math.abs(dy) > 6 && Math.abs(dy) > Math.abs(dx)) { drag = null; settle(x); return; }
          if (Math.abs(dx) <= 6) return;
          drag.locked = true;
          row.setPointerCapture(event.pointerId);
          row.setAttribute("data-dragging", "");
          getSelection()?.removeAllRanges();
        }
        drag.raw = drag.start + dx;
        const side = Math.sign(drag.raw);
        if (!reduced()) {
          const next = resist(drag.raw);
          setX(next);
          if (side) { row.setAttribute("data-side", side > 0 ? "leading" : "trailing"); setReveal(Math.abs(next)); }
        }
        row.toggleAttribute("data-armed", !!side && rest(side) > 0 && Math.abs(drag.raw) >= row.clientWidth * 0.6);
        drag.samples.push({ t: performance.now(), x: drag.raw });
        if (drag.samples.length > 12) drag.samples.shift();
      });
      const release = (event: PointerEvent, canceled: boolean) => {
        if (!drag || drag.id !== event.pointerId) return;
        const d = drag; drag = null;
        row.removeAttribute("data-dragging");
        if (row.hasPointerCapture(event.pointerId)) row.releasePointerCapture(event.pointerId);
        if (!d.locked) { if (!canceled && openCtl?.el === row) settle(0); return; }
        const now = performance.now();
        const old = d.samples.find((s) => now - s.t <= 100) ?? d.samples[0];
        const v = old && now > old.t ? (d.raw - old.x) / (now - old.t) : 0;
        const side = Math.sign(d.raw);
        const outer = side ? actionOf(side) : null;
        if (canceled || !outer) { settle(0); return; }
        const stop = rest(side);
        const flick = Math.sign(v) === side && Math.abs(v) > 1.1 && Math.abs(d.raw) >= stop * 0.8;
        if (Math.abs(d.raw) >= row.clientWidth * 0.6 || flick) { commit(side, outer); return; }
        const p = d.raw + v * 140, ps = Math.sign(p);
        settle(Math.abs(p) > rest(ps) * 0.5 ? ps * rest(ps) : 0);
      };
      row.addEventListener("pointerup", (event) => release(event, false));
      row.addEventListener("pointercancel", (event) => release(event, true));
      row.addEventListener("lostpointercapture", (event) => { if (drag && event.pointerId === drag.id) release(event, true); });

      const collapse = () => {
        if (reduced()) {
          row.style.opacity = "0";
          window.setTimeout(() => { row.hidden = true; row.style.opacity = ""; setX(0); finish(); }, 160);
          return;
        }
        row.style.height = `${row.offsetHeight}px`;
        void row.offsetHeight;
        row.style.height = "0px"; row.style.paddingTop = "0px"; row.style.paddingBottom = "0px"; row.style.opacity = "0";
        window.setTimeout(() => { row.hidden = true; row.style.cssText = ""; setX(0); finish(); }, 310);
      };
      // slide: -1 or 1 to slide the row out of that side first, 0 to collapse in place.
      const remove = (slide: number) => {
        if (openCtl?.el === row) openCtl = null;
        if (slide && !reduced()) {
          window.clearTimeout(timer);
          row.setAttribute("data-armed", "");
          row.setAttribute("data-side", slide > 0 ? "leading" : "trailing");
          setReveal(row.clientWidth);
          setX(slide * row.clientWidth);
          window.setTimeout(collapse, 200);
        } else collapse();
      };
      const restore = () => {
        row.hidden = false;
        row.style.cssText = "";
        if (reduced()) { row.style.opacity = "0"; void row.offsetHeight; row.style.opacity = ""; return; }
        const natural = row.offsetHeight;
        row.style.height = "0px"; row.style.paddingTop = "0px"; row.style.paddingBottom = "0px"; row.style.opacity = "0";
        void row.offsetHeight;
        row.style.height = `${natural}px`; row.style.paddingTop = ""; row.style.paddingBottom = ""; row.style.opacity = "";
        window.setTimeout(() => { row.style.height = ""; }, 320);
      };
      ctls.set(row, { restore });

      // A pointer swipe or tap leaves focus where it was; only the menu path moves it.
      function commit(side: number, button: HTMLButtonElement) {
        const keep = button.dataset.keep === "true";
        if (!run(row, button.dataset.rowAction!, button.dataset.label!, !keep)) { settle(0); return; }
        if (keep) { settle(0); return; }
        remove(side);
      }

      // Tapping a revealed action.
      row.querySelectorAll<HTMLButtonElement>("[data-underlay] [data-row-action]").forEach((button) => button.addEventListener("mousedown", (event) => event.preventDefault()));
      row.querySelectorAll<HTMLButtonElement>("[data-underlay] [data-row-action]").forEach((button) => button.addEventListener("click", (event) => {
        event.preventDefault();
        commit(Math.sign(x) || (lead?.contains(button) ? 1 : -1), button);
      }));

      // The menu: same actions, keyboard first.
      menu.querySelectorAll<HTMLButtonElement>("[data-row-action]").forEach((button) => button.addEventListener("click", (event) => {
        event.preventDefault();
        const keep = button.dataset.keep === "true";
        const hadFocus = row.contains(document.activeElement);
        menu.hidePopover();
        if (!run(row, button.dataset.rowAction!, button.dataset.label!, !keep)) return;
        if (x !== 0) settle(0);
        if (keep) { if (hadFocus) more(row)?.focus(); } else { if (hadFocus) focusNeighbour(row); remove(0); }
      }));
      const items = () => Array.from(menu.querySelectorAll<HTMLButtonElement>("button"));
      menu.addEventListener("toggle", (event) => {
        const open = (event as ToggleEvent).newState === "open";
        more(row)?.setAttribute("aria-expanded", String(open));
        if (open) { if (openCtl?.el === row) settle(0); items()[0]?.focus(); }
      });
      menu.addEventListener("keydown", (event) => {
        const list = items(), i = list.indexOf(document.activeElement as HTMLButtonElement);
        const next = event.key === "ArrowDown" ? list[(i + 1) % list.length] : event.key === "ArrowUp" ? list[(i - 1 + list.length) % list.length] : event.key === "Home" ? list[0] : event.key === "End" ? list.at(-1) : null;
        if (next) { event.preventDefault(); next.focus(); }
      });
      more(row)?.setAttribute("aria-expanded", "false");
      more(row)?.setAttribute("aria-haspopup", "true");
    });

    undo.addEventListener("click", () => {
      if (!previous) return;
      const { row, state } = previous;
      ctls.get(row)?.restore();
      const text = row.querySelector<HTMLElement>("[data-row-state]")!; text.textContent = state; text.hidden = !state;
      row.querySelector<HTMLElement>("[data-row-more]")?.focus();
      root.dispatchEvent(new CustomEvent("haze:swipe-undo", { bubbles: true, detail: { id: row.dataset.rowId } }));
      status.textContent = `Restored ${row.dataset.label}.`; previous = null; undo.hidden = true;
    });
    root.setAttribute("data-enhanced", "");
  }
  const init = () => document.querySelectorAll<HTMLElement>("[data-haze-swipe-actions]").forEach(enhance);
  init();
  if (!document.documentElement.hasAttribute("data-haze-swipe-actions-listener")) {
    document.documentElement.setAttribute("data-haze-swipe-actions-listener", "");
    document.addEventListener("astro:page-load", init);
    document.addEventListener("pointerdown", (event) => { if (openCtl && !openCtl.el.contains(event.target as Node)) openCtl.close(); });
    document.addEventListener("keydown", (event) => { if (event.key === "Escape" && openCtl) openCtl.close(); });
  }
</script>
```
