Skip to main content

SwipeableRow

Swipe a row to reveal actions, as in Mail: trailing actions from the right, leading ones from the left. With fullSwipe, a long swipe runs the outermost action. Opening a row closes any other open row, and tapping an open row closes it. Wrap a ListItem in it, inside a List.

import { SwipeableRow } from 'patine-ui';
Loading…
<List title="Inbox" style={{ width: 340 }}>
  {mail.map((subject) => (
    <SwipeableRow
      key={subject}
      fullSwipe
      leadingActions={[{ label: 'Pin', variant: 'primary', onPress: () => {} }]}
      trailingActions={[
        { label: 'Delete', variant: 'destructive', onPress: () => remove(subject) },
        { label: 'More', onPress: () => {} },
      ]}
    >
      <ListItem title={subject} description="Swipe me" />
    </SwipeableRow>
  ))}
</List>

Try the props​

Props
<SwipeableRow
trailingActions={[{ label: 'Delete', variant: 'destructive', onPress: remove }]}
/>

Example: a to-do list​

A task list: swipe right to complete a task, swipe left to flag or delete it. A full swipe left deletes in one go, and every action is also in the screen reader's actions menu.

Loading…
<List title={`${tasks.filter((t) => !t.done).length} to do`} style={{ width: '100%', maxWidth: 400 }}>
  {tasks.map((task) => (
    <SwipeableRow
      key={task.id}
      fullSwipe
      leadingActions={[
        { label: task.done ? 'Undo' : 'Done', icon: <Icon name="check" color="#FFFFFF" />, color: '#16A34A', onPress: () => set(task.id, { done: !task.done }) },
      ]}
      trailingActions={[
        { label: 'Delete', icon: <Icon name="trash" color="#FFFFFF" />, variant: 'destructive', onPress: () => setTasks((all) => all.filter((t) => t.id !== task.id)) },
        { label: task.flagged ? 'Unflag' : 'Flag', icon: <Icon name="flag" color="#FFFFFF" />, color: '#F59E0B', onPress: () => set(task.id, { flagged: !task.flagged }) },
      ]}
    >
      <ListItem
        title={task.title}
        titleStyle={task.done ? { textDecorationLine: 'line-through', opacity: 0.5 } : undefined}
        description={task.due}
        showChevron={false}
        trailing={task.flagged ? <Icon name="flag" color="warning" size="sm" accessibilityLabel="Flagged" /> : null}
      />
    </SwipeableRow>
  ))}
  {tasks.length ? null : <Text color="textSecondary">Nothing left. Enjoy the weekend.</Text>}
</List>

Actions​

Each action has a label, an optional icon drawn above it, an onPress, and a variant: 'destructive' (red), 'primary', or 'default' (a neutral gray). Pass color for a colour of your own. The first action on each side sits at the edge, and it's the one a full swipe runs.

Accessibility​

  • On iOS and Android, screen readers reach the action buttons right after the row, without swiping.
  • On the web, focus the row and press the left arrow to open the trailing actions or the right arrow for the leading ones, then Tab to them; Escape closes the row. Closed actions are hidden from the keyboard.
  • Action buttons are as tall as the row and at least 74pt wide.

Props​

PropTypeDefaultDescription
childrenReactNode—The row, usually a ListItem.
trailingActionsSwipeAction[]—Revealed by swiping left; the first sits at the edge.
leadingActionsSwipeAction[]—Revealed by swiping right.
fullSwipebooleanfalseA long swipe runs the edge action.
backgroundColorstringthe List's fillThe row's fill over the actions.
disabledbooleanfalse
onOpenChange(side: 'leading' | 'trailing' | null) => void—
styleStyleProp<ViewStyle>—
theme / designprovider'sAction widths: 74 iOS, 88 Material, 80 web and brand.

SwipeAction​

FieldTypeDescription
labelstringShown and read by screen readers.
iconReactNodeDrawn above the label.
variant'default' | 'primary' | 'destructive'The fill.
colorstringA fill of your own.
onPress() => voidThe row closes after it runs.