@napacitor/action-sheet
Native action sheet plugin (corresponds to @capacitor/action-sheet).
Installation
To use npm:
npm install @napacitor/action-sheet
To use yarn:
yarn add @napacitor/action-sheet
Sync native files:
npx nap sync
Usage
import { ActionSheet } from '@napacitor/action-sheet';
const { index, canceled } = await ActionSheet.showActions({
title: 'Choose an action',
options: [
{ title: 'Upload' },
{ title: 'Share' },
{ title: 'Delete', style: ActionSheetButtonStyle.Destructive },
],
cancelable: true,
});
console.log(index, canceled); // 2 false / -1 true (canceled)
How It Works
Wraps the Page.DisplayActionSheet API described in the .NET MAUI documentation, switching to the UI thread via MainThread.InvokeOnMainThreadAsync before showing the native action sheet. The returned index follows the order of the options array and is -1 when canceled. On Windows, MAUI falls back to a ContentDialog-style selection popup.
Permissions
Android
No additional configuration required.
iOS
No additional configuration required.
Windows
No additional configuration required.
API
showActions(options)
Shows the action sheet; when canceled, index is -1 and canceled is true.
Returns: Promise<ShowActionsResult>
| Param | Type |
|---|---|
options | ShowActionsOptions |
Interfaces
ActionSheetButton
| Prop | Type | Description |
|---|---|---|
title | string | Button label. |
style | ActionSheetButtonStyle | Button style. iOS-only semantics; DisplayActionSheet has no matching parameter, so the native side currently ignores it (destructive button styling requires platform code); ignored on web as well. |
icon | string | Button icon. Web-only; ignored on native. |
ShowActionsOptions
| Prop | Type | Description |
|---|---|---|
title | string | Action sheet title. |
message | string | Message shown below the title. iOS-only semantics; DisplayActionSheet has no matching parameter, so the native side ignores it. |
options | ActionSheetButton[] | Available options. Must not be empty (at least one option with a title), otherwise INVALID_ARGUMENTS is thrown. |
cancelable | boolean | Whether tapping outside the sheet cancels it (default false). When true, a 'Cancel' button is provided (without it the sheet cannot be dismissed by tapping outside); canceling returns {index: -1, canceled: true}. |
ShowActionsResult
| Prop | Type | Description |
|---|---|---|
index | number | Index of the clicked option (0-based); -1 when canceled. |
canceled | boolean | Whether the sheet was canceled. |