Ir al contenido
Español
Acciones al deslizar viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

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.

Úsalo para

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

Busca otra opción cuando

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

Uso

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>
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
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[].collapsebooleanfalseCollapses the row height first, then calls back. Good for delete.
fullSwipebooleanfalseSwiping past fullSwipeThreshold of the row width runs the main action directly.
fullSwipeThresholdnumber0.6Where a full swipe triggers, as a fraction of the row width.
actionWidthnumber76Width of each button in px, at least 44.
disabledbooleanfalseDisables swiping. The buttons stay reachable by keyboard.
childrenReactNode—The row content.
...restHTMLAttributes—Other attributes go to the root element, such as role="listitem" and className.
SwipeGroupcomponent—Wraps a set of SwipeActions so only one row is open at a time. Other props go to its div.

Accesibilidad

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

Movimiento

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.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

SwipeActions.jsxswipe-actions.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Listas
Carrusel en arco viene con Pro. La vista previa aparece al desbloquearlo.
Carrusel cilíndrico viene con Pro. La vista previa aparece al desbloquearlo.