import{o as s,a,y as n}from"./vue-libs.b44bc779.js";const e={class:"van-doc-markdown-body"},d=n(`

ActionSheet

Intro

The pop-up modal panel at the bottom contains multiple options related to the current situation.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

import { createApp } from 'vue';
import { ActionSheet } from 'vant';

const app = createApp();
app.use(ActionSheet);

Usage

Basic Usage

Use actions prop to set options of action-sheet.

<van-cell is-link title="Basic Usage" @click="show = true" />
<van-action-sheet v-model:show="show" :actions="actions" @select="onSelect" />
import { ref } from 'vue';
import { Toast } from 'vant';

export default {
  setup() {
    const show = ref(false);
    const actions = [
      { name: 'Option 1' },
      { name: 'Option 2' },
      { name: 'Option 3' },
    ];
    const onSelect = (item) => {
      show.value = false;
      Toast(item.name);
    };

    return {
      show,
      actions,
      onSelect,
    };
  },
};

Show Cancel Button

<van-action-sheet
  v-model:show="show"
  :actions="actions"
  cancel-text="Cancel"
  close-on-click-action
  @cancel="onCancel"
/>
import { ref } from 'vue';
import { Toast } from 'vant';

export default {
  setup() {
    const show = ref(false);
    const actions = [
      { name: 'Option 1' },
      { name: 'Option 2' },
      { name: 'Option 3' },
    ];
    const onCancel = () => Toast('cancel');

    return {
      show,
      actions,
      onCancel,
    };
  },
};

Show Description

<van-action-sheet
  v-model:show="show"
  :actions="actions"
  cancel-text="Cancel"
  description="Description"
  close-on-click-action
/>
import { ref } from 'vue';

export default {
  setup() {
    const show = ref(false);
    const actions = [
      { name: 'Option 1' },
      { name: 'Option 2' },
      { name: 'Option 3', subname: 'Description' },
    ];

    return {
      show,
      actions,
    };
  },
};

Option Status

<van-action-sheet
  v-model:show="show"
  :actions="actions"
  cancel-text="Cancel"
  close-on-click-action
/>
import { ref } from 'vue';

export default {
  setup() {
    const show = ref(false);
    const actions = [
      { name: 'Colored Option', color: '#ee0a24' },
      { name: 'Disabled Option', disabled: true },
      { name: 'Loading Option', loading: true },
    ];

    return {
      show,
      actions,
    };
  },
};

Custom Panel

<van-action-sheet v-model:show="show" title="Title">
  <div class="content">Content</div>
</van-action-sheet>

<style>
  .content {
    padding: 16px 16px 160px;
  }
</style>

API

Props

AttributeDescriptionTypeDefault
v-model:showWhether to show ActionSheetbooleanfalse
actionsOptionsActionSheetAction[][]
titleTitlestring-
cancel-textText of cancel buttonstring-
descriptionDescription above the optionsstring-
closeableWhether to show close iconbooleantrue
close-iconClose icon namestringcross
durationTransition duration, unit secondnumber | string0.3
roundWhether to show round cornerbooleantrue
overlayWhether to show overlaybooleantrue
overlay-classCustom overlay classstring | Array | object-
overlay-styleCustom overlay styleobject-
lock-scrollWhether to lock background scrollbooleantrue
lazy-renderWhether to lazy render util appearedbooleantrue
close-on-popstateWhether to close when popstatebooleantrue
close-on-click-actionWhether to close when an action is clickedbooleanfalse
close-on-click-overlayWhether to close when overlay is clickedbooleantrue
safe-area-inset-bottomWhether to enable bottom safe area adaptationbooleantrue
teleportSpecifies a target element where ActionSheet will be mountedstring | Element-
before-close v3.1.4Callback function before close(action: string) => boolean | Promise<boolean>-

Data Structure of ActionSheetAction

KeyDescriptionType
nameTitlestring
subnameSubtitlestring
colorText colorstring
classNameclassName for the optionstring | Array | object
loadingWhether to be loading statusboolean
disabledWhether to be disabledboolean
callbackCallback function after clickedaction: ActionSheetAction

Events

EventDescriptionArguments
selectEmitted when an option is clickedaction: ActionSheetAction, index: number
cancelEmitted when the cancel button is clicked-
openEmitted when opening ActionSheet-
closeEmitted when closing ActionSheet-
openedEmitted when ActionSheet is opened-
closedEmitted when ActionSheet is closed-
click-overlayEmitted when overlay is clickedevent: MouseEvent

Slots

NameDescriptionSlotProps
defaultCustom content
descriptionCustom description above the options
cancel v3.0.10Custom the content of cancel button
action v3.4.0Custom the content of action{ action: ActionSheetAction, index: number }

Types

The component exports the following type definitions:

import type { ActionSheetProps, ActionSheetAction } from 'vant';

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-action-sheet-max-height80%-
--van-action-sheet-header-height48px-
--van-action-sheet-header-font-sizevar(--van-font-size-lg)-
--van-action-sheet-description-colorvar(--van-text-color-2)-
--van-action-sheet-description-font-sizevar(--van-font-size-md)-
--van-action-sheet-description-line-heightvar(--van-line-height-md)-
--van-action-sheet-item-backgroundvar(--van-background-color-light)-
--van-action-sheet-item-font-sizevar(--van-font-size-lg)-
--van-action-sheet-item-line-heightvar(--van-line-height-lg)-
--van-action-sheet-item-text-colorvar(--van-text-color)-
--van-action-sheet-item-disabled-text-colorvar(--van-text-color-3)-
--van-action-sheet-subname-colorvar(--van-text-color-2)-
--van-action-sheet-subname-font-sizevar(--van-font-size-sm)-
--van-action-sheet-subname-line-heightvar(--van-line-height-sm)-
--van-action-sheet-close-icon-size22px-
--van-action-sheet-close-icon-colorvar(--van-gray-5)-
--van-action-sheet-close-icon-padding0 var(--van-padding-md)-
--van-action-sheet-cancel-text-colorvar(--van-gray-7)-
--van-action-sheet-cancel-padding-topvar(--van-padding-xs)-
--van-action-sheet-cancel-padding-colorvar(--van-background-color)-
--van-action-sheet-loading-icon-size22px-
`,17),l=[d],h={__name:"README",setup(o,{expose:t}){return t({frontmatter:{}}),(p,r)=>(s(),a("div",e,l))}};export{h as default};