Swipeable Row

Animated

A row that swipes open to actions; a full swipe commits.

Source
$npx @dinachi/cli@latest add swipeable-row
  • Weekly digest

    product@dinachi.dev · 09:04

  • Your invoice is ready

    billing · yesterday

  • Re: motion tier scope

    sam · Tuesday

onDismiss
dismissAt
actionWidth

Usage

import { Archive, Trash2 } from "lucide-react"
import { SwipeableRow, SwipeableRowGroup } from "@/components/ui/swipeable-row"

export function Inbox({ onArchive, onDelete }: { onArchive: () => void; onDelete: () => void }) {
  return (
    <SwipeableRowGroup>
      <SwipeableRow
        actions={[
          { label: "Archive Weekly digest", icon: <Archive className="h-4 w-4" />, onSelect: onArchive },
          { label: "Delete Weekly digest", icon: <Trash2 className="h-4 w-4" />, onSelect: onDelete, destructive: true },
        ]}
        onDismiss={onDelete}
      >
        Weekly digest
      </SwipeableRow>
    </SwipeableRowGroup>
  )
}

Examples

  • Weekly digest

    product@dinachi.dev · 09:04

  • Your invoice is ready

    billing · yesterday

  • Re: motion tier scope

    sam · Tuesday

Flick to open, drag past halfway to commit.
import { SwipeableRow, SwipeableRowGroup } from '@/components/ui/swipeable-row';
import { Archive, Trash2 } from 'lucide-react';

export function Example() {
  return (
    <SwipeableRowGroup>
      {rows.map((row) => (
        <SwipeableRow
          key={row.id}
          actions={[
            { label: `Archive ${row.title}`, icon: <Archive className="h-4 w-4" />, onSelect: () => archive(row.id) },
            { label: `Delete ${row.title}`, icon: <Trash2 className="h-4 w-4" />, onSelect: () => remove(row.id), destructive: true },
          ]}
          onDismiss={() => remove(row.id)}
        >
          {row.title}
        </SwipeableRow>
      ))}
    </SwipeableRowGroup>
  );
}

Notes

Release

On release the row projects where its momentum would carry it and compares that point with the thresholds. A short fast flick opens the row; a slow drag that stops short falls back. The spring takes over at the pointer's velocity.

Dismiss threshold

Past dismissAt the destructive action fills the row before release. Without onDismiss there is no threshold or destructive layer.

Refusing a change

onSelect and onDismiss both get change details. details.reason is "trigger-press", "swipe" or "imperative-action" for an agent. details.cancel() in onDismiss slides the row back.

When to use it

  • Long touch lists with per-row actions: mail, tasks, notifications.
  • For a short list, show the buttons instead.
  • Keep actions reversible; a destructive one still needs an undo.

Behaviour

  • Opening a row in a SwipeableRowGroup closes the open one. Outside a group, each row is independent.
  • The open resting point is actionWidth times the number of actions.
  • The row can travel its full width.
  • Row content is yours; the component owns only the gesture.

Motion tier

Needs motion. add --all skips it; install with add --motion or by name.

API

actions
agent
SwipeableRowAction[]
Revealed under the row, right to left. Each is { label, icon, onSelect(details), destructive?, disabled?, className? }. Required.
onDismiss
agent
(details) => void
Runs on a full swipe. Omit it and the row only opens. details.cancel() slides it back.
dismissAtnumber = 0.5
Fraction of row width past which release commits onDismiss.
actionWidthnumber = 68
Width of each action button in px.
aria-label
agent
string
Names the row. Without it the agent uses its text.

Agent

Inside an AgentProvider, it appears in agent.snapshot() as region.

Reads

label

The row's aria-label, or its text with each piece kept apart.

actions

dismiss when the row has onDismiss, otherwise none.

disabled

On an action's button, true when that action is disabled.

Actions

press()

On an action, listed as a button named by its label even while hidden. Runs onSelect.

dismiss()

On the row, when onDismiss is set. Runs it, then slides the row off.

An agent's press runs through the action's onSelect and its dismiss through onDismiss. isAgentChange(details) is true for both; details.cancel() refuses either, tells the agent, and a refused dismiss leaves the row in place. A disabled action refuses on its own.

await agent.act({
  steps: [{ ref: "Archive Weekly digest", action: "press" }],
})

Accessibility

  • Every action is a real button, reachable without swiping.
  • Buttons are icon-only, so label is the name. Make it specific, as in Archive Weekly digest.
  • Focusing an action opens the row.
  • Reduced motion disables the drag and shows the actions beside the content.