How it works
The content layer sits over a row of real buttons and follows the finger with translateX (written to a CSS variable and updated straight in the DOM each frame). Each button draws a coloured pill inset from the row edges that grows from 0.6 to full size as it is uncovered; the pill is a long rounded shape cut with clip-path, so on a full swipe the main action stretches across the row by animating the clip, without layout changes. An 8px check decides the direction: only clearly horizontal moves take over, the rest scroll the page. Pointer movement is converted for scaled containers. Past the buttons there is rubber-band resistance. On release, the last 100ms of velocity decides: a quick flick opens or closes, otherwise it snaps by halfway. Style hooks: --ds-swipe-radius (row corners, for tile lists), --ds-swipe-bg, --ds-swipe-pill-radius and --ds-swipe-pill-inset.
Use it for
- Quick actions on one row in mobile message, notification or order lists: read, pin, delete.
- Frequent actions where a “more” menu costs an extra tap.
- Inbox-style lists where a full swipe deletes or archives.
Look elsewhere when
- Mostly desktop pages: mouse users rarely think to drag; put buttons at the row end or show them on hover.
- The only way to do something important: gestures are invisible, so offer another entry point too.
- Rows with their own horizontal swiping, such as carousels and sliders: the gestures conflict.
Usage
import { SwipeActions, SwipeGroup } from './SwipeActions.jsx'
export function MessageList({ messages, onRead, onDelete }) {
return (
<SwipeGroup role="list">
{messages.map((m) => (
<SwipeActions
key={m.id}
role="listitem"
fullSwipe
actions={[
{ key: 'read', label: 'Read', tone: 'accent', onClick: () => onRead(m.id) },
{ key: 'delete', label: 'Delete', tone: 'danger', collapse: true, onClick: () => onDelete(m.id) },
]}
>
<MessageRow message={m} />
</SwipeActions>
))}
</SwipeGroup>
)
}Props
| Prop | Type | Default | What it does |
|---|---|---|---|
actions | { key, label, icon?, tone?, onClick, collapse? }[] | — | The revealed actions, left to right; the last is the main action. tone is 'neutral', 'accent', 'warning' or 'danger'. Labels are yours, so the component has no built-in text. |
actions[].collapse | boolean | false | Collapses the row height first, then calls back. Good for delete. |
fullSwipe | boolean | false | Swiping past fullSwipeThreshold of the row width runs the main action directly. |
fullSwipeThreshold | number | 0.6 | Where a full swipe triggers, as a fraction of the row width. |
actionWidth | number | 76 | Width of each button in px, at least 44. |
disabled | boolean | false | Disables swiping. The buttons stay reachable by keyboard. |
children | ReactNode | — | The row content. |
...rest | HTMLAttributes | — | Other attributes go to the root element, such as role="listitem" and className. |
SwipeGroup | component | — | Wraps a set of SwipeActions so only one row is open at a time. Other props go to its div. |
Accessibility
- The actions are real <button> elements, always in the tab order; tabbing to one opens the row and focus leaving the row closes it. After a keyboard action that does not delete the row, it stays open with focus on a visible button.
- Buttons have text labels (icons are aria-hidden), so every action works without gestures.
- A focused button shows a ring around its pill, inside the row, since the clipped row would cut a ring on the button's edge.
- touch-action: pan-y keeps vertical list scrolling working.
- Reduced motion makes snapping and collapsing instant; dragging still follows the finger.
Motion
Snap after release: 320ms ease-out, with the pills growing from 0.6 to full size in step. Main action stretch and retract: 200ms ease-out on clip-path and translate. After a full swipe the content slides out in 200ms; the row collapses in 240ms ease-in-out. Rubber-band damping applies when overdragging.
Add it to your project
Pro members copy a prompt and their coding agent installs the source, the same way as the free components.
SwipeActions.jsxswipe-actions.csstokens.cssREADME.md
Both files install together. The stylesheet reads the design tokens in tokens.css and carries fallbacks, so it also works alone.





