Skip to main content

ActionSheet

ActionSheet asks "what do you want to do with this?": a short list of actions in a BottomSheet, such as Share, Edit or Delete. The iOS design floats the actions in a rounded card with Cancel in a card of its own; Material and the web list them as rows on the sheet, with icons if you pass them.

import { ActionSheet } from 'patine-ui';
Behaves like
Loading…
<>
  <DemoButton title="Photo options" onPress={() => setOpen(true)} />
  <Text style={{ marginTop: 12, textAlign: 'center' }}>Last action: {last}</Text>
  <ActionSheet
    open={open}
    onOpenChange={setOpen}
    title="Profile photo"
    actions={[
      { label: 'Take photo', onPress: () => setLast('Take photo') },
      { label: 'Choose from library', onPress: () => setLast('Choose from library') },
      { label: 'Remove photo', destructive: true, onPress: () => setLast('Remove photo') },
    ]}
  />
</>

Try the props​

Behaves like
Props
presentation
showCancel
<ActionSheet
open={open}
onOpenChange={setOpen}
title="Profile photo"
actions={actions}
/>

Example: message actions​

A team chat: the options button on a message opens its actions. Pin and Unpin swap with the message's state, Delete is destructive, and the change shows once the sheet has closed.

Behaves like
Loading…
<VStack gap="sm" style={{ width: '100%', maxWidth: 420 }}>
  {messages.map((m) => (
    <HStack key={m.id} gap="sm" align="flex-start">
      <VStack gap="xs" style={{ flex: 1 }}>
        <HStack gap="sm" align="center">
          <Text weight="semibold">{m.from}</Text>
          <Text size="sm" color="textSecondary">{m.time}</Text>
          {m.pinned ? <Badge variant="secondary">Pinned</Badge> : null}
        </HStack>
        <Text>{m.text}</Text>
      </VStack>
      <Button size="icon" variant="ghost" accessibilityLabel={`Options for ${m.from}'s message`} onPress={() => setTarget(m.id)}>
        <Icon name="moreVertical" />
      </Button>
    </HStack>
  ))}
  {status ? <Text size="sm" color="textSecondary">{status}</Text> : null}
  <ActionSheet
    open={target !== null}
    onOpenChange={(open) => !open && setTarget(null)}
    title={message ? `${message.from}, ${message.time}` : undefined}
    message={message?.text}
    actions={
      message
        ? [
            { label: 'Reply', icon: <Icon name="reply" />, onPress: () => setStatus(`Replying to ${message.from}…`) },
            { label: 'Copy text', icon: <Icon name="copy" />, onPress: () => setStatus('Copied to the clipboard.') },
            {
              label: message.pinned ? 'Unpin' : 'Pin to channel',
              icon: <Icon name="pin" />,
              onPress: () => update(message.id, { pinned: !message.pinned }),
            },
            {
              label: 'Delete message',
              icon: <Icon name="trash" />,
              destructive: true,
              onPress: () => {
                setMessages((all) => all.filter((m) => m.id !== message.id));
                setStatus('Message deleted.');
              },
            },
          ]
        : []
    }
  />
</VStack>

Actions​

Each action is { label, onPress, description, icon, selected, destructive, disabled, testID }:

  • description adds a second line under the label.
  • icon is any node shown before the label, such as a 24 px icon from the icon set you already use.
  • selected marks the current choice with a ✓.
  • destructive draws the label in the theme's danger colour, for Delete, Remove or Sign out.
  • disabled greys the action out and ignores taps.

A tap closes the sheet through onOpenChange(false), and the action's onPress runs once the sheet has finished closing. That way an action can open another sheet, a modal or the image picker: iOS shows only one modal at a time.

Icons and descriptions​

Icons suit the Material and web rows, where they line up at the start. Switch the example to Android or Web to see them as rows.

Behaves like
Loading…
<>
  <DemoButton title="Share" onPress={() => setOpen(true)} />
  <ActionSheet
    open={open}
    onOpenChange={setOpen}
    title="Share “Summer trip”"
    actions={[
      { label: 'Copy link', description: 'Anyone with the link can view', icon: <Icon name="link" /> },
      { label: 'Send in a message', icon: <Icon name="messageSquare" /> },
      { label: 'Invite people', description: 'They can add photos too', icon: <Icon name="users" /> },
      { label: 'Download all', icon: <Icon name="download" />, disabled: true },
    ]}
  />
</>

A choice with a ✓​

For a short choice that applies right away, such as a sort order or video quality, mark the current one with selected.

Behaves like
Loading…
<>
  <DemoButton title={`Sort by: ${sort}`} onPress={() => setOpen(true)} />
  <ActionSheet
    open={open}
    onOpenChange={setOpen}
    title="Sort by"
    actions={SORTS.map((label) => ({
      label,
      selected: label === sort,
      onPress: () => setSort(label),
    }))}
  />
</>

For a longer list, or one with search, use Select.

Confirm a delete​

title names what the actions apply to; message adds a line under it, such as what a Delete removes. With one destructive action, the sheet is a confirmation.

Behaves like
Loading…
<>
  <DemoButton title={`Delete a note (${notes} left)`} onPress={() => setOpen(true)} disabled={!notes} />
  <ActionSheet
    open={open}
    onOpenChange={setOpen}
    title="Delete this note?"
    message="It's removed from all your devices."
    showCancel
    actions={[{ label: 'Delete note', destructive: true, onPress: () => setNotes((n) => n - 1) }]}
  />
</>

Show it from a call​

useActionSheet shows a sheet without an open state of your own, as showActionSheetWithOptions does in @expo/react-native-action-sheet. Render the actionSheet it returns once, then call show with the sheet's props from any handler. It needs no provider.

Loading…
<View style={{ gap: 8 }}>
  {FILES.map((file) => (
    <Pressable key={file} onPress={() => openMenu(file)} style={{ padding: 14, borderRadius: 12, backgroundColor: '#F4F2EE' }}>
      <Text>{file} ⋯</Text>
    </Pressable>
  ))}
  <Text style={{ textAlign: 'center' }}>Last action: {last}</Text>
  {actionSheet}
</View>

show takes every ActionSheet prop except open, and onOpenChange is optional. hide() closes the sheet from code.

Cancel​

The iOS design ends with a Cancel button in its own card, as iOS does. Material and web sheets don't: they close on a backdrop tap, a swipe down or Back. showCancel turns it on or off for any design, and cancelLabel renames it. Cancel, the backdrop, a swipe and Back all call onOpenChange(false) without running an action.

Bottom sheet or modal​

presentation is the same as on BottomSheet: 'auto' (default) is a centered modal on wide web windows and a bottom sheet everywhere else. Anything else the sheet takes, such as bottomInset or onClosed, goes in sheetProps. An action sheet doesn't expand to full screen (expandable: false), and only the Material and web designs show the grab handle; sheetProps can turn either back on.

Accessibility​

Each action is a button named by its label and description, marked disabled or selected, and the title is a header. On the web, arrow keys move between actions and Escape closes the sheet.

Props​

PropTypeDefaultDescription
openbooleanfalseShow or hide (animated). Keep it mounted and flip this.
onOpenChange(open: boolean) => void—Called with false when the user closes it: on any action, Cancel, a backdrop tap, a swipe down and Back. Set open to false here. Not called when open changes from your code.
actionsActionSheetAction[]requiredThe actions, top to bottom.
titlestring—What the actions apply to.
messagestring—A line under the title.
showCancelbooleantrue iOS / false Material and webA Cancel button after the actions.
cancelLabelstring'Cancel'
presentation'auto' | 'bottomSheet' | 'modal''auto'Bottom sheet or centered modal.
sheetPropsPartial<BottomSheetProps>—Passed to the BottomSheet, except open, onOpenChange and children.
themeDeepPartial<Theme>—Theme override. See Theming.
design'brand' | 'ios' | 'material' | 'web' | 'native'from PatineProviderThe look to follow, over the provider's: brand, iOS, Material or web, or 'native' for the platform's own.
stylesSlotStyles<ActionSheetSlot>—Slot styles: group (the iOS cards), header / title / message (the title block), action / actionLabel / actionDescription / check (each row, its label, description and ✓), cancel / cancelLabel.
testIDstring—On the sheet; Cancel gets ${testID}-cancel.
interface ActionSheetAction {
label: string;
onPress?: () => void; // runs after the sheet has closed
description?: string; // a second line under the label
icon?: ReactNode;
selected?: boolean; // a ✓ for the current choice
destructive?: boolean; // theme danger colour
disabled?: boolean;
testID?: string;
}

const { show, hide, actionSheet } = useActionSheet();
show(options: Omit<ActionSheetProps, 'open' | 'onOpenChange'> & { onOpenChange?: (open: boolean) => void });