Skip to content
API 风格:

ActionSheet ​

Mobile bottom action menu: a list of items (adjacent entries sharing a group are grouped, disabled entries are grayed, color: 'danger' marks a destructive action), an optional header title, and a cancel button. Visibility is a controlled modelValue (same contract as Dialog); the mask and the overlay stack reuse this repo's overlay system (Escape closes only the topmost layer, scroll locking, focus trapping).

Grouping, disabled semantics, mask-close decisions and class names all come from the pure functions in @lh-ui/share/core/action-sheet; when cancelText is not given the cancel button label is taken from the locale pack.

Basic Usage ​

items holds the actions (name is required, subname is a secondary line). Clicking an enabled item emits select (the item reference plus the global index) and closes the sheet:

Basic Usage
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhButton, LhActionSheet } from '@lh-ui/vue3'

const visible = ref(false)
const items = [
  { name: 'Take a Photo', subname: 'From the camera' },
  { name: 'Choose from Album' },
]
</script>

<template>
  <!-- Basic usage -->
  <LhButton @click="visible = true">Open Action Sheet</LhButton>
  <LhActionSheet v-model="visible" title="Choose an Action" :items="items" />
</template>
vue
<script>
import { LhButton, LhActionSheet } from '@lh-ui/vue3'

export default {
  components: { LhButton, LhActionSheet },
  data() {
    return {
      visible: false,
      items: [
        { name: 'Take a Photo', subname: 'From the camera' },
        { name: 'Choose from Album' },
      ],
    }
  },
}
</script>

<template>
  <!-- Basic usage -->
  <LhButton @click="visible = true">Open Action Sheet</LhButton>
  <LhActionSheet v-model="visible" title="Choose an Action" :items="items" />
</template>

Groups, Disabled and Danger ​

Adjacent entries sharing a group are sectioned with a gray divider; disabled grays an item out and blocks clicks; color: 'danger' uses the danger token while any other color is applied inline:

Groups and Danger Actions
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhButton, LhActionSheet } from '@lh-ui/vue3'
import type { LhActionSheetItem } from '@lh-ui/vue3'

const visible = ref(false)
const items: LhActionSheetItem[] = [
  { name: 'Set as Wallpaper' },
  { name: 'Edit Markers', group: 'edit' },
  { name: 'Rotate and Crop', group: 'edit' },
  { name: 'Delete', color: 'danger' },
]

function onSelect(item: LhActionSheetItem, index: number) {
  console.log(item.name, index)
}
</script>

<template>
  <!-- Groups and danger actions -->
  <LhButton @click="visible = true">Delete Photo</LhButton>
  <LhActionSheet v-model="visible" :items="items" cancel-text="Cancel" @select="onSelect" />
</template>
vue
<script>
import { LhButton, LhActionSheet } from '@lh-ui/vue3'

export default {
  components: { LhButton, LhActionSheet },
  data() {
    return {
      visible: false,
      items: [
        { name: 'Set as Wallpaper' },
        { name: 'Edit Markers', group: 'edit' },
        { name: 'Rotate and Crop', group: 'edit' },
        { name: 'Delete', color: 'danger' },
      ],
    }
  },
  methods: {
    onSelect(item, index) {
      console.log(item.name, index)
    },
  },
}
</script>

<template>
  <!-- Groups and danger actions -->
  <LhButton @click="visible = true">Delete Photo</LhButton>
  <LhActionSheet v-model="visible" :items="items" cancel-text="Cancel" @select="onSelect" />
</template>

Close Behavior ​

Clicking the mask (closeOnClickMask, default true) and pressing Escape (when this sheet is the topmost layer) both close the sheet and emit update:modelValue; the cancel button emits cancel (pass an empty string to hide it):

vue
<!-- Do not close on mask click (items / cancel / Escape still work) -->
<LhActionSheet v-model="visible" :items="items" :close-on-click-mask="false" />

<!-- Hide the cancel button -->
<LhActionSheet v-model="visible" :items="items" cancel-text="" />

API ​

ActionSheet Props ​

PropDescriptionTypeDefault
modelValueVisibility (controlled)booleanfalse
itemsAction entriesLhActionSheetItem[]() => []
titleHeader titlestring—
cancelTextCancel button label (empty string hides it; defaults to the locale word for "cancel")string—
closeOnClickMaskClose on mask clickbooleantrue
safeAreaInsetBottomBottom safe-area paddingbooleantrue
sxsx quick-layout props (applied to the panel)LhSxProps—

ActionSheet Items ​

PropDescriptionTypeDefault
nameAction namestring—
subnameSecondary description (gray second line)string—
disabledDisable the entry (grayed, not clickable)booleanfalse
colorText color ('danger' uses the danger token; other values apply inline)string—
groupGroup key (adjacent entries sharing it are grouped; no key joins the default group)string—

ActionSheet Events ​

EventDescriptionCallback
update:modelValueVisibility change(value: boolean)
selectEmitted on click of an enabled item (the sheet then closes)(item: LhActionSheetItem, index: number)
cancelEmitted on cancel button click (the sheet then closes)—

Accessibility ​

  • The panel root carries role="dialog" and aria-modal="true"; aria-label comes from title or a fixed fallback
  • Opening traps focus inside the panel and restores it on close (the same focus trap implementation as Dialog / Drawer)
  • Each item is a real <button>; disabled entries carry the disabled attribute

Beauty of tradition, foundation of code