SwipeToReveal

Updated: Oct 14, 2026
SwipeToReveal wraps one focusable child and gives it a trailing tray of one to three icon-only actions. The child stays the row’s primary target; the tray holds contextual secondary commands that are not worth a permanent focus stop.
The shell itself is never focusable. It owns the reveal and hide keys, the spring motion, tray focus, the tray’s tabIndex and aria-hidden state, and a polite announcement each time the tray opens or closes.
Place revealable rows and ordinary rows together in one VerticalList with no gaps between them. The shell deliberately spans the list’s horizontal inset and re-applies that inset inside the slot, so the row can slide the full width without clipping at either screen edge — keep the list edge to edge and do not add horizontal page padding around it.

Usage

import {
  ListItem,
  SwipeToReveal,
  VerticalList,
} from '@wearables-ui-toolkit/mrbd';

function ConversationList() {
  return (
    <VerticalList ariaLabel="Conversations">
      {conversations.map(conversation => (
        <SwipeToReveal
          key={conversation.id}
          actions={[
            {
              icon: archiveIcon,
              contentDescription: 'Archive',
              onClick: () => archive(conversation.id),
            },
            {
              icon: muteIcon,
              contentDescription: 'Mute',
              onClick: () => mute(conversation.id),
            },
          ]}
        >
          <ListItem
            title={conversation.name}
            subtitle={conversation.preview}
            timestamp={conversation.timestamp}
            avatarSrc={conversation.photoUrl}
            avatarAlt={conversation.name}
            onClick={() => open(conversation.id)}
          />
        </SwipeToReveal>
      ))}
    </VerticalList>
  );
}

Props

The full prop type is SwipeToRevealProps. It extends HTMLAttributes<HTMLDivElement>, redeclaring children and the two capture handlers below; every other standard div attribute is forwarded to the root element, and the component forwards its ref there too.
PropTypeDefaultDescription
children
ReactElement
required
The single focusable element placed in the slot. A row, card, or chip is typical.
actions
readonly [SwipeToRevealAction, SwipeToRevealAction?, SwipeToRevealAction?]
required
Ordered tray actions. One is required; at most three are rendered.
actionsShownAnnouncement
string
'Actions shown'
Polite live-region announcement when the tray opens. Pass a localized value.
actionsHiddenAnnouncement
string
'Actions hidden'
Polite live-region announcement when the tray closes. Pass a localized value.
className
string
''
Extra class on the root element, appended after the component’s own class.
onKeyDownCapture
KeyboardEventHandler
—
Runs before the component’s own capture handling. Calling preventDefault skips it.
onKeyUpCapture
KeyboardEventHandler
—
Runs before the component’s own capture handling. Calling preventDefault skips it.

Types and enums

interface SwipeToRevealAction {
  icon: IconSource;
  contentDescription: string;
  onClick: () => void;
}
Each action renders as an icon-only Button inside a start-aligned ButtonGroup at the trailing edge. contentDescription becomes that button’s accessible name, so it is required — there is no visible label. onClick takes no arguments; close over whatever the action needs.
Optional tuple slots you leave empty are skipped, so an actions value that computes to [archive, undefined] renders a single action rather than a gap.

Behavior

Revealing and hiding

  • Right, while focus is inside the slot and the tray is hidden, reveals the tray on key release.
  • Left, while the tray is open and focus is on its first action, hides it on key release. Left from any later action moves focus within the tray as usual.
  • Up or Down, while the tray is open, hides it and lets focus move on: the key itself is not consumed, so the surrounding list still moves focus to the neighbouring row.
  • Escape or the browser back key, while the tray is open, hides it and consumes both the press and the release so the route does not also navigate back.
Reveal and hide are decided on key release, and the matching key press is consumed, so a single press never both reveals the tray and moves focus. If a different key hides the tray between a press and its release, the stale release is dropped rather than re-toggling.
Reveal is a directional-input interaction, not a pointer interaction: there is no drag or touch swipe to open the tray.

Focus

Toggling the tray keeps focus inside the component. Opening the tray moves focus to its first action; closing it returns focus to the first focusable element in the slot, falling back to the slot itself when the child has no focusable descendant. Up and Down are the exception: the tray closes, focus returns to the slot, and the key still reaches the list, which then moves focus to the neighbouring row.
While hidden, the tray is aria-hidden and its buttons carry a negative tab index; once the fade-out settles it is also hidden outright and stops receiving pointer events, so it can never be reached by accident. The shell itself is not a focus stop.
Once an action runs, the tray stays open — hide it from your handler’s state update, or leave it to the user’s next Left, Up, Down, or Back.

Layout and motion

The tray is absolutely positioned against the trailing edge and the slot sits above it, so the tray is only visible once the slot has moved. The slot translates horizontally by the measured tray width while the tray fades in, both driven by the same spring. When the actions array changes while the tray is open, the slot re-measures and re-settles against the new tray width.
When the user prefers reduced motion, both springs snap straight to their target instead of settling, so the tray appears and disappears without travel. The open and closed states are otherwise identical.

Accessibility

The component supplies: the accessible name of each action button (from contentDescription), the aria-hidden and tab-order state of the tray, and a visually hidden polite live region. The live region announces “Actions shown” and “Actions hidden” by default. Pass localized actionsShownAnnouncement and actionsHiddenAnnouncement values for the languages your app supports.
Application responsibilities. Supply a focusable child with its own accessible name, localized tray announcements, and action descriptions that name the command rather than the icon (“Archive”, not “Box icon”).
Assistive-technology users who never send a Right key never see the tray, so anything essential has to stay reachable on the row itself.
  • Keep the row’s essential action on the row itself and reserve the tray for contextual extras.
  • Give every action a short, imperative contentDescription.
  • Localize both tray announcements with actionsShownAnnouncement and actionsHiddenAnnouncement.
  • Keep actions stable between renders when nothing changed; a new array while the tray is open re-measures and re-animates it.
  • Test the closed, open, and action-focused states, both list edges, mixed revealable and plain rows, and the return to the row after an action runs.

Avoid

  • Avoid putting more than three actions in the tray; extras are dropped.
  • Avoid hiding a destructive or essential action behind the reveal.
  • Avoid wrapping a non-focusable child; the slot needs a real focus target.
  • Avoid adding horizontal padding, a gap, or a rounded wrapper around revealable rows.
  • Avoid attaching your own onKeyDownCapture that calls preventDefault unconditionally; that disables reveal and hide entirely.