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.tabIndex and aria-hidden state, and a polite announcement each time the tray opens or closes.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.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>
);
}
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.| Prop | Type | Default | Description |
|---|---|---|---|
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. |
interface SwipeToRevealAction {
icon: IconSource;
contentDescription: string;
onClick: () => void;
}
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.actions value that computes to [archive, undefined] renders a single action rather than a gap.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.actions array changes while the tray is open, the slot re-measures and re-settles against the new tray width.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.contentDescription.actionsShownAnnouncement and actionsHiddenAnnouncement.actions stable between renders when nothing changed; a new array while the tray is open re-measures and re-animates it.onKeyDownCapture that calls preventDefault unconditionally; that disables reveal and hide entirely.