Skip to content
Slotted

Action sheet

A sheet of short actions that rises from the bottom edge of the screen, for choices made with a thumb.

Installation

The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.

bash
pnpm add @slotted/react @slotted/theme @slotted/themes
tsx
import { ActionSheet, ActionSheetCancel, ActionSheetContent,  ActionSheetDefaultsProvider, ActionSheetGroup, ActionSheetHeader,  ActionSheetItem, ActionSheetList, ActionSheetMessage,  ActionSheetSeparator, ActionSheetTitle, ActionSheetTrigger } from '@slotted/react';

Actions, a title and a way out

The trigger opens a sheet that holds a title, an optional message, a list of actions and a cancel. Choosing an action closes the sheet and reports its value as the result of the request. The cancel closes it with the reason dismiss, and with no words of its own it shows the cancel text of the language in force. The sheet is a dialog that names its list through the title, so a screen reader announces the title for the dialog and again for the list. Use an action sheet for a short list of choices on a phone; on a pointer device the same actions read better as a menu.

Tones

tone paints the words, the icon and the highlight of an action in one of five tones: accent, secondary, success, warning or danger. danger marks the destructive action, which goes first in the list where it is noticed. When the first action that can run is danger, focus enters the sheet on the cancel instead, so a press on Enter right after opening cannot destroy anything.

Groups and separators

A group names a run of related actions with a label that is also its accessible name. A separator draws a rule between two runs. The groups, the separator and the actions stay in one list with one tab stop, so the arrow keys cross from one group to the next.

Descriptions and unavailable actions

A description is the action’s second line, muted, and joins its accessible description. A disabled action keeps its place in the list and in the arrow key order, takes aria-disabled and refuses the press, so a reader can still reach it and read why it is unavailable.

Loading

loading marks an action whose work has started. The spinner takes the icon’s box and the label does not move, the action carries aria-busy and refuses a second press, and the sheet stays open until the application clears loading and closes it. Call preventDefault() on the select event so the press does not close the sheet. Press the first action: the export takes 2.5 seconds.

Keeping the sheet open

closeOnSelect={false} on the sheet, or the closeOnSelect input in Angular, keeps it open after any action is chosen, for a list where the reader makes several choices. closeOnSelect on one action overrides the sheet for that action. messages replaces the cancel’s words, which here read Done. Press the pallets, then dispatch the route.

Loaded: none

Reading the result

The request that moves the sheet carries reason, the way the move was asked for: pointer or keyboard from the trigger, select from an action, dismiss from the cancel, escape, outsidePress, back or programmatic. When the reason is select, result holds the chosen action’s value. onOpenChange receives the request in React and openChangeRequest emits it in Angular; both bindings take open for a sheet the application controls. There is no promise-returning controller: the request already carries the answer.

Last request: none

Beside the page

A modal sheet makes the page inert, locks the scroll and paints a scrim. modal={false} paints no scrim, leaves the page operable and contains no focus, for a sheet that stays open beside the work. A press outside it still closes the sheet. Open the sheet, then press Scan parcel.

What may close it

escape, outsidePress and back each take close or none. With none, that way of leaving is ignored. The cancel and the actions still close the sheet, so a sheet that must be answered always has an exit. back applies to a modal sheet: the browser’s back button or a phone’s back gesture closes the sheet and stays on the page.

Focus

Focus enters on the first action that can run. initialFocus names another element, or false to move nothing. On close, focus returns to the element that held it, and finalFocus names another. In React both take a ref, and in Angular they take the element. Here focus enters on Reprint shipping label and returns to Scan next parcel.

Decided once

ActionSheetDefaultsProvider in React and provideActionSheetDefaults in Angular set modal, mount, escape, outsidePress, back and closeOnSelect for every sheet below them. A sheet that states a value of its own keeps it. Here Picking inherits closeOnSelect={false} and outsidePress="none", so a choice leaves it open; Packing states closeOnSelect and closes.

An action that navigates is an anchor. In React, render returns the anchor and receives the action’s props. In Angular, the directive goes on an a element. The role and the keyboard are the same as for a button, and choosing the link closes the sheet.

Accessibility

KeyEffectFocus
Tabmoves between the two tabbable stops of the panel — the list, which is one stop by roving tabindex, and the cancel — and wraps from the last to the first while modal. It does not close the sheet, which is the departure from the menu pattern: the menu is the content of a dialog, and a dialog contains focusthe item the list last held, or the cancel
Shift+Tabthe same, backwards, wrapping from the first stop to the last while modalthe previous tabbable stop inside the panel
Escapeasks the topmost layer to close, carrying the reason escape; refused when escape is none, and a layer that refuses stops the request reaching the layer beneath itreturns to the element that held it when the sheet opened
ArrowDownmoves to the next item of the list, disabled items included, wrapping from the last to the firstthe next item
ArrowUpmoves to the previous item, wrapping from the first to the lastthe previous item
Homemoves to the first itemthe first item
Endmoves to the last itemthe last item
Printable charactermoves to the next item whose textValue, or whose label text, begins with the characters typed within the typeahead timeoutthe matching item
Enteron an item, runs onSelect and then asks to close with the reason select, carrying the item's value as the result, unless closeOnSelect is false or onSelect called preventDefault; a disabled or loading item does nothing. On the cancel, asks to close with the reason dismissreturns to the element that held it when the sheet opened, once the sheet closes; stays on the item otherwise
Spaceas Enteras Enter
  • No WAI-ARIA APG pattern describes an action sheet, so the layer answers Dialog (Modal) — w3.org/WAI/ARIA/apg/patterns/dialog-modal/ — and the list answers Menu — w3.org/WAI/ARIA/apg/patterns/menubar/. The panel is role="dialog", aria-modal while modal, named by the title and described by the message; the list is role="menu", named by the same title, and every action is a native button with role="menuitem".
  • The list is one tab stop. ArrowDown and ArrowUp move between actions and wrap, Home and End reach the ends, and a printable character moves to the next action whose label, or textValue, begins with it. Tab moves between the list and the cancel and does not close — the one departure from the menu pattern, because the menu is the content of a dialog and the dialog contains focus. A reader leaves with Escape or the cancel.
  • A screen reader hears the title twice on entry, once for the dialog and once for the menu. Without a name the menu would be anonymous to a reader moving by widget, and the repetition is the cheaper cost.
  • Focus enters on the first action that can run. When that action is destructive it enters on the cancel, which is the least destructive action the dialog pattern’s first note recommends; with no cancel, on the first action that is not danger. It returns to the element that held it on close, except after a press outside a non-modal sheet, where the reader was going somewhere else.
  • A disabled or loading action keeps its place in the ring and takes aria-disabled, as the menu pattern requires; a loading one also carries aria-busy. The cancel is never disabled, because a sheet that cannot be left is a trap. Every action is a control’s height tall, which the theme raises to the 44-pixel comfortable target under a coarse pointer; on a phone the label grows from 14 to 16 pixels with it.
  • The layer is drawer’s, so the sheet answers everything a drawer from the bottom answers: a touch on its body drags it and a release toward the edge asks to close with the reason pointer, which cancel() refuses like any other close; with the virtual keyboard open the sheet lands above the keys. Nothing of that needs a key: Escape and the cancel are the keyboard’s way out.
  • A mouse or a pen moving over an action focuses it, so one row is lit whichever device drives; a finger does not, because focus moving under a touch that is about to scroll would light rows at random.

API

action-sheet

Props

openboolean
Present at all means the consumer owns the state, for the life of the component. ActionSheet then asks and waits.
defaultOpenboolean
The value an uncontrolled sheet starts from, read once.
modalbooleanDefault true
On ActionSheet, ActionSheetDefaultsProviderWhether the page is inert, the scroll locked, focus contained and the scrim painted. false keeps the page operable and paints no scrim.
mount'active' | 'lazy' | 'eager'Default active
On ActionSheet, ActionSheetDefaultsProviderWhen the layer exists. active drops it once the exit is over, lazy builds it on the first open and keeps it, eager builds it up front and makes it inert.
escape'close' | 'none'Default close
On ActionSheet, ActionSheetDefaultsProviderWhether Escape asks to close. It reaches the topmost layer only.
outsidePress'close' | 'none'Default close
On ActionSheet, ActionSheetDefaultsProviderWhether a press outside the panel — on the scrim, or on the page behind a non-modal sheet — asks to close.
back'close' | 'none'Default close
On ActionSheet, ActionSheetDefaultsProviderThe platform’s way back — a phone’s gesture, a browser’s button — closes the sheet instead of leaving the page, while it is modal.
closeOnSelectbooleanDefault true
On ActionSheet, ActionSheetDefaultsProviderWhether choosing an action closes the sheet with the reason select.
messagesPartial<ActionSheetMessages>
Words laid over the language in force, key by key: the cancel’s words when it is given no children (cancel)
initialFocusRefObject<HTMLElement> | false
Where focus goes on opening. Unstated, the first action that can run, or the least destructive one when that action is danger. false moves nothing.
finalFocusRefObject<HTMLElement> | false
Where focus goes on closing. Unstated, the element that held it on opening.
valuestring
On ActionSheetItemWhat the close request carries as result when this action is chosen.
textValuestring
On ActionSheetItemWhat typeahead matches when the label is not plain text.
iconReactNode
On ActionSheetItemThe action’s visual, drawn in the mark column.
descriptionReactNode
On ActionSheetItemThe second line, which aria-describedby points at.
tone'accent' | 'secondary' | 'success' | 'warning' | 'danger'
On ActionSheetItemPaints the words, the mark and the highlight. danger is the destructive action.
disabledbooleanDefault false
On ActionSheetItemThe action cannot run. It stays focusable and takes aria-disabled.
loadingbooleanDefault false
On ActionSheetItemThe action is running: the ring takes the mark’s box, aria-busy is written, a second press is refused and the sheet stays open.
closeOnSelectboolean
On ActionSheetItemOverrides the sheet’s closeOnSelect for this action.
labelReactNode
On ActionSheetGroupRendered as the group-label part, and the group’s accessible name.

Events

NamePayloadWhen
onOpenChange(open: boolean, request: ActionSheetChangeRequest)Before the sheet moves, for every way it can: reason is pointer or keyboard from the trigger, pointer from a drag of the sheet that asks to close, select from an item, dismiss from the cancel, escape, outsidePress, back, or programmatic from the handle. result carries the chosen item’s value when the reason is select, and cancel() refuses the move before anything commits.
onSelect(event: ActionSheetSelectEvent)On ActionSheetItem, when an item that can run is activated, before the sheet asks to close. The event carries reason, value and the originating event; preventDefault() keeps the sheet open.
onClick, onKeyDown, onPointerMove, on every partthe element’s own eventsWhenever the element fires them. The consumer’s handler runs first, and preventDefault() refuses the action sheet’s own behavior.

Composition

render(props) => ReactNode
On ActionSheetTrigger, ActionSheetContent, ActionSheetTitle, ActionSheetMessage, ActionSheetItem, ActionSheetCancelSubstitutes the element. An item that navigates renders an anchor and keeps its role and keyboard; the trigger becomes the application’s own Button. The list, the groups and the separator are fixed, because their role is what they are.
refRef<ActionSheetHandle> on ActionSheet, Ref<HTMLElement> on every part
On ActionSheet, every partOn a part it reaches the element. On ActionSheet it is a handle with open(), close() and focus() — the actions a consumer cannot express declaratively.
containerElement | null
A parent for this layer alone instead of the shared portal root, passed to drawer.
useActionSheet()() => ActionSheetContextValue
On inside ActionSheetWhat the parts read: the open state, the identifiers, the axes and close(reason, result). It throws outside a sheet.
ActionSheetDefaultsProvider{ modal, mount, escape, outsidePress, back, closeOnSelect }
On a subtreeThe decisions an application takes once. A sheet that states any of them itself still wins.

Parts

PartElementRequiredPurpose
rootdiv, inside drawer’s panelYesThe action sheet’s own box, data-ui="action-sheet": a grid of header, list and footer that spans every row of drawer’s panel, so the list is the one row that scrolls when the sheet reaches its cap. The layer around it is drawer with side="bottom" and size="content", which owns the portal, the scrim, the role="dialog" panel, the slide, the drag and the width — here the action sheet’s --slotted-action-sheet-inline-size, handed to drawer’s sheet.
triggerbutton, or the element render returnsNodrawer’s trigger, rendered where it is written. aria-haspopup="dialog", aria-expanded and aria-controls. It is also the layer’s branch, so a press on it is not read as a press outside.
headerheaderNoThe title and the message, above a rule.
titleh2, or the element render returnsNoThe name of the dialog and of the list, set small: the title is the context and the actions are the content.
messagep, or the element render returnsNoThe dialog’s description, which aria-describedby points at when it is rendered.
listdiv with role="menu"YesOne tab stop for every action, by roving tabindex; the arrows, Home, End and typeahead move inside it. Named by the title. The one row of the panel that scrolls.
groupdiv with role="group"NoA run of related actions, named by its label.
group-labeldivNoThe group’s visible name, set muted and semibold above its actions.
itembutton with role="menuitem", or the element render returnsYesOne action, a control’s height tall — 44 pixels under a coarse pointer, where the theme raises it, and the density’s own height under a fine one. data-tone, data-disabled and data-loading; a disabled or loading item stays focusable and takes aria-disabled.
iconspan[aria-hidden]NoThe item’s visual, or the spinner while it is loading. Its column exists only when some item of the list draws one, so labels line up either way.
labelspanYesThe item’s words. It wraps and never truncates.
descriptionspanNoThe item’s second line, muted, which aria-describedby points at.
separatorhr with role="separator"NoA rule between runs of actions. Not focusable.
footerdiv, rendered by ActionSheetCancelNoThe band that holds the cancel, on the sunken surface, carrying the bottom safe-area inset where a phone’s home indicator sits.
cancelbutton, or the element render returnsNoThe explicit way out, asking to close with the reason dismiss. Never disabled. Its words default to the catalog’s cancel.

Theming

Each token is a CSS custom property: set it in a theme, or on any element to retune every action sheet inside it.

Action sheet tokens

TokenDefault
--slotted-action-sheet-footer-surfacevar(--slotted-surface-sunken, Canvas)
--slotted-action-sheet-highlightvar(--slotted-tone-secondary-subtle-hover, ButtonFace)
--slotted-action-sheet-highlight-activevar(--slotted-tone-secondary-subtle-active, ButtonFace)
--slotted-action-sheet-inline-size32rem
--slotted-action-sheet-rule-colorvar(--slotted-border-subtle, ButtonBorder)

Theme tokens it reads

TokenDefault
--slotted-border-subtleSet per scheme by the theme
--slotted-border-width-thin1px
--slotted-control-border-colorSet per scheme by the theme
--slotted-control-border-widthvar(--slotted-border-width-thin)
--slotted-control-font-familyvar(--slotted-font-family-sans)
--slotted-control-gap-lgcomfortable 8px · compact 6px · dense 6px
--slotted-control-height-lgcomfortable 38px · compact 32px · dense 30px
--slotted-control-padding-inline-lgcomfortable 16px · compact 12px · dense 10px
--slotted-control-radiusvar(--slotted-radius-sm)
--slotted-control-shadowSet per scheme by the theme
--slotted-control-surfaceSet per scheme by the theme
--slotted-control-transition-durationvar(--slotted-duration-short)
--slotted-control-transition-easingvar(--slotted-easing-standard)
--slotted-disabled-backgroundSet per scheme by the theme
--slotted-disabled-foregroundSet per scheme by the theme
--slotted-duration-short120ms
--slotted-easing-standardcubic-bezier(0.2, 0, 0, 1)
--slotted-focus-ring-colorSet per scheme by the theme
--slotted-focus-ring-offsetvar(--slotted-border-width-thick)
--slotted-focus-ring-widthvar(--slotted-border-width-thick)
--slotted-font-family-headingvar(--slotted-font-family-sans)
--slotted-font-family-sans'Geist Variable', ui-sans-serif, system-ui, sans-serif
--slotted-font-size-lg1rem
--slotted-font-size-md0.875rem
--slotted-font-size-sm0.8125rem
--slotted-font-weight-semibold600
--slotted-line-height-md1.5
--slotted-line-height-sm1.45
--slotted-space-10.125rem
--slotted-space-20.25rem
--slotted-space-40.5rem
--slotted-space-50.75rem
--slotted-space-61rem
--slotted-surface-sunkenSet per scheme by the theme
--slotted-textSet per scheme by the theme
--slotted-text-mutedSet per scheme by the theme
--slotted-tone-accent-subtle-activeSet per scheme by the theme
--slotted-tone-accent-surfaceSet per scheme by the theme
--slotted-tone-accent-textSet per scheme by the theme
--slotted-tone-danger-subtle-activeSet per scheme by the theme
--slotted-tone-danger-surfaceSet per scheme by the theme
--slotted-tone-danger-textSet per scheme by the theme
--slotted-tone-secondary-subtle-activeSet per scheme by the theme
--slotted-tone-secondary-subtle-hoverSet per scheme by the theme
--slotted-tone-secondary-surfaceSet per scheme by the theme
--slotted-tone-secondary-textSet per scheme by the theme
--slotted-tone-success-subtle-activeSet per scheme by the theme
--slotted-tone-success-surfaceSet per scheme by the theme
--slotted-tone-success-textSet per scheme by the theme
--slotted-tone-warning-subtle-activeSet per scheme by the theme
--slotted-tone-warning-surfaceSet per scheme by the theme
--slotted-tone-warning-textSet per scheme by the theme