ActionSheet Action sheet
Present bottom actions with disabled states, loading and close guards.
Import
Use <hui-action-sheet> with uni-app easycom. Import public types from @nscode/handy-uni. For ordinary Vue 3, install the preview plugin from @nscode/handy-uni/web and register its components.
Examples
Interact with the controls to see values and event results on the page.
<template>
<view>
<button @click="visible = true">操作 / Actions</button
><hui-action-sheet
ref="control"
v-model:visible="visible"
title="选择操作 / Choose action"
:items="items"
cancel-text="取消 / Cancel"
@update:visible="event0"
@select="event1"
@cancel="event2"
@close="event3"
@open="event4"
@opened="event5"
@closed="event6"
/>
<hui-button @click="() => control?.open()">open()</hui-button>
<hui-button @click="() => control?.close('api')">close()</hui-button>
<text>{{ lastEvent }}</text>
</view>
</template>
<script setup lang="ts">
import { ref } from 'vue'
const lastEvent = ref('No event yet')
const describe = (value: unknown) => {
try {
return JSON.stringify(value) ?? String(value)
} catch {
return String(value)
}
}
const control = ref()
const visible = ref(false)
const items = [
{ label: '编辑 / Edit', value: 'edit' },
{ label: '只读项 / Disabled', value: 'disabled', disabled: true },
{ label: '处理中 / Working', value: 'busy', loading: true }
]
const event0 = (arg0: unknown) => {
lastEvent.value = 'update:visible' + ': ' + [describe(arg0)].join(', ')
}
const event1 = (arg0: unknown, arg1: unknown) => {
lastEvent.value = 'select' + ': ' + [describe(arg0), describe(arg1)].join(', ')
}
const event2 = () => {
lastEvent.value = 'cancel'
}
const event3 = (arg0: unknown) => {
lastEvent.value = 'close' + ': ' + [describe(arg0)].join(', ')
}
const event4 = () => {
lastEvent.value = 'open'
}
const event5 = () => {
lastEvent.value = 'opened'
}
const event6 = () => {
lastEvent.value = 'closed'
}
</script>
The second select argument contains index. Disabled or loading items cannot be selected. Set closeOnClickAction=false to keep the panel open.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
visible | boolean | undefined | Controlled visibility; undefined is omitted and explicit false stays closed. |
defaultVisible | boolean | false | Initial uncontrolled visibility. |
items | ActionSheetItem[] | [] | Item data. |
title | string | — | Title. |
description | string | — | Description; an explicit empty string overrides fallback text. |
cancelText | string | — | Cancel action text; an empty string remains an explicit override. |
closeOnClickAction | boolean | true | Request closing after selecting an enabled action. |
closeOnClickOverlay | boolean | true | Request guarded closing when the overlay is clicked. |
beforeClose | ((reason: ActionSheetCloseReason) => unknown) | — | Close guard; false or rejection prevents closing. |
safeAreaInsetBottom | boolean | true | Reserve the bottom safe area. |
zIndex | number | — | Layer z-index; allocated from the current page stack when omitted. |
rootPortal | boolean | false | Try to mount at the page root; support varies by platform. |
Root attributes: common props. A Boolean default of undefined supports inheritance; explicit false overrides it. Other Boolean props default to false unless listed otherwise.
Events
| Event | Parameters | Description |
|---|---|---|
update:visible | (value: boolean) | Request a visibility update. |
select | (item: ActionSheetItem, ctx: { index: number }) | An option was selected; draft changes may not yet be committed. |
cancel | () | Cancellation action. |
close | (reason: ActionSheetCloseReason) | Closing started after guards passed. |
open | () | Opening started. |
opened | () | Enter animation finished. |
closed | () | Leave animation finished. |
Slots
| Slot | Parameters | Description |
|---|---|---|
title | — | Custom title region; replaces its fallback content. |
description | — | Custom description region; replaces its fallback content. |
default | — | Main content. |
item | { item, index } | Custom item region; replaces its fallback content. |
cancel | — | Custom cancel region; replaces its fallback content. |
Methods
| Method | Signature | Description |
|---|---|---|
open | (): void | Open the uncontrolled panel or request a controlled update. |
close | (reason?: ActionSheetCloseReason | undefined): Promise<boolean> | Request closing through configured guards. |
Types
ActionSheetProps、ActionSheetItem、ActionSheetCloseReason、ActionSheetExpose、ActionSheetEmits are available from @nscode/handy-uni.
export interface ActionSheetItem {
label: string
value?: string | number
description?: string
color?: string
disabled?: boolean
loading?: boolean
}
export type ActionSheetCloseReason = PopupCloseReason | 'cancel' | 'select'
Platform notes
| Behavior | uni-app H5 | WeChat Mini Program | App-vue | Ordinary Vue 3 Web (preview) |
|---|---|---|---|---|
| Basic interaction | Supported; device checks pending | Supported; device checks pending | Supported; device checks pending | Supported by the web platform adapter |
Follow the smoke checklist. Device evidence is tracked separately; unit tests do not establish device acceptance.