액션 시트 (ion-action-sheet)
액션 시트(Action Sheet)는 일련의 옵션을 보여 주는 다이얼로그예요. 앱 콘텐츠 위에 나타나며, 사용자가 앱과 상호작용을 다시 시작하려면 직접 닫아야 해요. 파괴적(destructive) 옵션은 ios 모드에서 확실히 구분되게 표시돼요. 액션 시트를 닫는 방법은 여러 가지예요. 백드롭을 탭하거나 데스크톱에서 escape 키를 누르는 것도 포함돼요.
출처: 문서
본문
Encapsulation: scoped
액션 시트는 옵션 집합을 보여 주는 다이얼로그예요. 앱 콘텐츠 위에 나타나며, 사용자가 앱과 상호작용을 재개하기 전에 수동으로 닫아야 해요. 파괴적 옵션은 ios 모드에서 명확하게 표시돼요. 액션 시트를 닫는 방법은 여러 가지인데, 백드롭을 탭하거나 데스크톱에서 escape 키를 누르는 방법이 포함돼요.
Inline Action Sheets (Recommended)
ion-action-sheet는 템플릿에 컴포넌트를 직접 작성해서 사용할 수 있어요. 이렇게 하면 Action Sheet를 표시하기 위해 연결해야 하는 핸들러 수가 줄어들어요.
JavaScript
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet trigger="open-action-sheet" header="Actions"></ion-action-sheet>
<script>
var actionSheet = document.querySelector('ion-action-sheet');
actionSheet.buttons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
</script>
Angular
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonActionSheet, IonButton } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonActionSheet, IonButton],
})
export class ExampleComponent {
public actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
}
src/app/example.component.html
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet trigger="open-action-sheet" header="Actions" [buttons]="actionSheetButtons"></ion-action-sheet>
React
import React from 'react';
import { IonActionSheet, IonButton } from '@ionic/react';
function Example() {
return (
<>
<IonButton id="open-action-sheet">Open</IonButton>
<IonActionSheet
trigger="open-action-sheet"
header="Actions"
buttons={[
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
]}
></IonActionSheet>
</>
);
}
export default Example;
Vue
<template>
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet trigger="open-action-sheet" header="Actions" :buttons="actionSheetButtons"></ion-action-sheet>
</template>
<script setup lang="ts">
import { IonActionSheet, IonButton } from '@ionic/vue';
const actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
</script>
Using isOpen
ion-action-sheet의 isOpen 프로퍼티를 사용하면 개발자가 앱 상태에서 Action Sheet의 표시 상태를 제어할 수 있어요. 즉 isOpen이 true로 설정되면 Action Sheet가 표시되고, false로 설정되면 Action Sheet가 닫혀요.
isOpen은 단방향 데이터 바인딩을 사용해요. 그래서 Action Sheet가 닫혀도 자동으로 false로 설정되지는 않아요. 개발자는 ionActionSheetDidDismiss나 didDismiss 이벤트를 리슨해서 isOpen을 false로 설정해야 해요. 이유는 ion-action-sheet의 내부가 애플리케이션 상태와 밀접하게 결합되는 것을 막기 위해서예요. 단방향 데이터 바인딩에서는 Action Sheet가 반응형 변수가 제공하는 boolean 값에만 신경 쓰면 돼요. 양방향 데이터 바인딩에서는 Action Sheet가 boolean 값뿐 아니라 반응형 변수 자체의 존재까지 신경 써야 해요. 이는 비결정적(non-deterministic) 동작을 유발하고 앱을 디버깅하기 어렵게 만들 수 있어요.
JavaScript
<ion-button onclick="actionSheet.isOpen = true">Open</ion-button>
<ion-action-sheet header="Actions"></ion-action-sheet>
<script>
var actionSheet = document.querySelector('ion-action-sheet');
actionSheet.buttons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
actionSheet.addEventListener('ionActionSheetDidDismiss', (event) => {
actionSheet.isOpen = false;
});
</script>
Angular
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonActionSheet, IonButton } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonActionSheet, IonButton],
})
export class ExampleComponent {
isActionSheetOpen = false;
public actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
setOpen(isOpen: boolean) {
this.isActionSheetOpen = isOpen;
}
}
src/app/example.component.html
<ion-button (click)="setOpen(true)">Open</ion-button>
<ion-action-sheet
[isOpen]="isActionSheetOpen"
header="Actions"
[buttons]="actionSheetButtons"
(didDismiss)="setOpen(false)"
></ion-action-sheet>
React
import React, { useState } from 'react';
import { IonActionSheet, IonButton } from '@ionic/react';
function Example() {
const [isOpen, setIsOpen] = useState(false);
return (
<>
<IonButton onClick={() => setIsOpen(true)}>Open</IonButton>
<IonActionSheet
isOpen={isOpen}
header="Actions"
buttons={[
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
]}
onDidDismiss={() => setIsOpen(false)}
></IonActionSheet>
</>
);
}
export default Example;
Vue
<template>
<ion-button @click="setOpen(true)">Open</ion-button>
<ion-action-sheet
:is-open="isOpen"
header="Actions"
:buttons="actionSheetButtons"
@didDismiss="setOpen(false)"
></ion-action-sheet>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { IonActionSheet, IonButton } from '@ionic/vue';
const isOpen = ref(false);
const actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
const setOpen = (state: boolean) => {
isOpen.value = state;
};
</script>
Controller Action Sheets
actionSheetController는 Action Sheet가 언제 표시되고 닫힐지에 대해 더 세밀한 제어가 필요할 때 사용할 수 있어요.
JavaScript
<ion-button onclick="presentActionSheet()">Open</ion-button>
<script>
async function presentActionSheet() {
const actionSheet = document.createElement('ion-action-sheet');
actionSheet.header = 'Actions';
actionSheet.buttons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
document.body.appendChild(actionSheet);
await actionSheet.present();
}
</script>
Angular
src/app/example.component.ts
import { Component } from '@angular/core';
import { ActionSheetController, IonButton } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonButton],
})
export class ExampleComponent {
constructor(private actionSheetCtrl: ActionSheetController) {}
async presentActionSheet() {
const actionSheet = await this.actionSheetCtrl.create({
header: 'Actions',
buttons: [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
],
});
await actionSheet.present();
}
}
src/app/example.component.html
<ion-button (click)="presentActionSheet()">Open</ion-button>
React
import React from 'react';
import { IonButton, useIonActionSheet } from '@ionic/react';
function Example() {
const [present] = useIonActionSheet();
return (
<IonButton
onClick={() =>
present({
header: 'Actions',
buttons: [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
],
})
}
>
Open
</IonButton>
);
}
export default Example;
Vue
<template>
<ion-button @click="presentActionSheet">Open</ion-button>
</template>
<script setup lang="ts">
import { IonButton, actionSheetController } from '@ionic/vue';
const presentActionSheet = async () => {
const actionSheet = await actionSheetController.create({
header: 'Actions',
buttons: [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
],
});
await actionSheet.present();
};
</script>
Buttons
버튼의 role 프로퍼티는 destructive 또는 cancel이 될 수 있어요. role이 없는 버튼은 플랫폼 기본 모양을 가져요. cancel 역할의 버튼은 배열에서 어디에 있든 항상 맨 아래 버튼으로 로드돼요. 다른 모든 버튼은 buttons 배열에 추가된 순서대로 표시돼요. 참고: destructive 버튼은 항상 배열의 첫 번째 버튼이 되어 맨 위 버튼이 되도록 권장해요. 게다가 백드롭을 탭해서 액션 시트가 닫히면 cancel 역할의 버튼 핸들러가 실행돼요.
버튼은 ActionSheetButton의 data 프로퍼티를 통해 데이터를 전달받을 수도 있어요. 이 데이터는 onDidDismiss 메서드의 반환 값에서 data 필드를 채워요.
Collecting Role Information on Dismiss
didDismiss 이벤트가 발생하면 이벤트 상세의 data와 role 필드를 사용해 Action Sheet가 어떻게 닫혔는지에 대한 정보를 모을 수 있어요.
JavaScript
<style>
.container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
flex-direction: column;
}
</style>
<div class="container">
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
header="Example header"
sub-header="Example subheader"
></ion-action-sheet>
</div>
<script>
var actionSheet = document.querySelector('ion-action-sheet');
actionSheet.buttons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
actionSheet.addEventListener('ionActionSheetDidDismiss', (event) => {
console.log(JSON.stringify(event.detail, null, 2));
});
</script>
Angular
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonActionSheet, IonButton } from '@ionic/angular';
import type { OverlayEventDetail } from '@ionic/core';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['./example.component.css'],
imports: [IonActionSheet, IonButton],
})
export class ExampleComponent {
public actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
constructor() {}
logResult(event: CustomEvent<OverlayEventDetail>) {
console.log(JSON.stringify(event.detail, null, 2));
}
}
src/app/example.component.html
<div class="container">
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
header="Example header"
subHeader="Example subheader"
[buttons]="actionSheetButtons"
(didDismiss)="logResult($event)"
></ion-action-sheet>
</div>
src/app/example.component.css
.container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 100%;
}
React
src/main.tsx
import React from 'react';
import { IonActionSheet, IonButton } from '@ionic/react';
import type { OverlayEventDetail } from '@ionic/core';
import './main.css';
function Example() {
const logResult = (result: OverlayEventDetail) => {
console.log(JSON.stringify(result, null, 2));
};
return (
<div className="container">
<IonButton id="open-action-sheet">Open</IonButton>
<IonActionSheet
trigger="open-action-sheet"
header="Example header"
subHeader="Example subheader"
buttons={[
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
]}
onDidDismiss={({ detail }) => logResult(detail)}
></IonActionSheet>
</div>
);
}
export default Example;
src/main.css
.container {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
height: 100%;
}
Vue
<style>
.container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
flex-direction: column;
}
</style>
<template>
<div class="container">
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
header="Example header"
sub-header="Example subheader"
:buttons="actionSheetButtons"
@didDismiss="logResult($event)"
></ion-action-sheet>
</div>
</template>
<script setup lang="ts">
import { IonActionSheet, IonButton } from '@ionic/vue';
const actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
const logResult = (event: CustomEvent) => {
console.log(JSON.stringify(event.detail, null, 2));
};
</script>
Console
Console messages will appear here when logged from the example above.
Theming
Action Sheet는 scoped 캡슐화를 사용해요. 즉 런타임에 각 스타일에 추가 클래스를 붙여 CSS를 자동으로 범위(scope)를 한정해요. scoped 셀렉터를 CSS로 덮어쓰려면 높은 특정성(specificity)을 가진 셀렉터가 필요해요.
Styling
create 메서드의 cssClass에 커스텀 클래스를 전달하고, 그 클래스를 사용해 호스트와 내부 요소에 커스텀 스타일을 추가하는 것을 권장해요. 이 프로퍼티는 공백으로 구분된 여러 클래스를 받을 수도 있어요.
/* DOES NOT WORK - not specific enough */
.action-sheet-group {
background: #e5e5e5;
}
/* Works - pass "my-custom-class" in cssClass to increase specificity */
.my-custom-class .action-sheet-group {
background: #e5e5e5;
}
JavaScript
<style>
ion-action-sheet.my-custom-class .action-sheet-group {
background: #f58840;
}
ion-action-sheet.my-custom-class .action-sheet-title {
color: #fff;
}
ion-action-sheet.my-custom-class .action-sheet-cancel::after {
background: #e97223;
}
ion-action-sheet.my-custom-class .action-sheet-button,
ion-action-sheet.my-custom-class .action-sheet-button.ion-focused {
color: #000000;
}
@media (any-hover: hover) {
ion-action-sheet.my-custom-class .action-sheet-button:hover {
color: #000000;
}
}
ion-action-sheet.my-custom-class ion-backdrop {
opacity: 0.6;
}
</style>
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
class="my-custom-class"
header="Example header"
sub-header="Example subheader"
></ion-action-sheet>
<script>
var actionSheet = document.querySelector('ion-action-sheet');
actionSheet.buttons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
</script>
Angular
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonActionSheet, IonButton } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['./example.component.css'],
imports: [IonActionSheet, IonButton],
})
export class ExampleComponent {
public actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
constructor() {}
}
src/app/example.component.html
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
class="my-custom-class"
header="Example header"
subHeader="Example subheader"
[buttons]="actionSheetButtons"
></ion-action-sheet>
src/global.css
/* Note: These styles should be located in your global stylesheet */
ion-action-sheet.my-custom-class .action-sheet-group {
background: #f58840;
}
ion-action-sheet.my-custom-class .action-sheet-title {
color: #fff;
}
ion-action-sheet.my-custom-class .action-sheet-cancel::after {
background: #e97223;
}
ion-action-sheet.my-custom-class .action-sheet-button,
ion-action-sheet.my-custom-class .action-sheet-button.ion-focused {
color: #000000;
}
@media (any-hover: hover) {
ion-action-sheet.my-custom-class .action-sheet-button:hover {
color: #000000;
}
}
ion-action-sheet.my-custom-class ion-backdrop {
opacity: 0.6;
}
React
src/main.tsx
import React from 'react';
import { IonActionSheet, IonButton } from '@ionic/react';
import './main.css';
function Example() {
return (
<>
<IonButton id="open-action-sheet">Open</IonButton>
<IonActionSheet
trigger="open-action-sheet"
className="my-custom-class"
header="Example header"
subHeader="Example subheader"
buttons={[
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
]}
></IonActionSheet>
</>
);
}
export default Example;
src/main.css
ion-action-sheet.my-custom-class .action-sheet-group {
background: #f58840;
}
ion-action-sheet.my-custom-class .action-sheet-title {
color: #fff;
}
ion-action-sheet.my-custom-class .action-sheet-cancel::after {
background: #e97223;
}
ion-action-sheet.my-custom-class .action-sheet-button,
ion-action-sheet.my-custom-class .action-sheet-button.ion-focused {
color: #000000;
}
@media (any-hover: hover) {
ion-action-sheet.my-custom-class .action-sheet-button:hover {
color: #000000;
}
}
ion-action-sheet.my-custom-class ion-backdrop {
opacity: 0.6;
}
Vue
<style>
ion-action-sheet.my-custom-class .action-sheet-group {
background: #f58840;
}
ion-action-sheet.my-custom-class .action-sheet-title {
color: #fff;
}
ion-action-sheet.my-custom-class .action-sheet-cancel::after {
background: #e97223;
}
ion-action-sheet.my-custom-class .action-sheet-button,
ion-action-sheet.my-custom-class .action-sheet-button.ion-focused {
color: #000000;
}
@media (any-hover: hover) {
ion-action-sheet.my-custom-class .action-sheet-button:hover {
color: #000000;
}
}
ion-action-sheet.my-custom-class ion-backdrop {
opacity: 0.6;
}
</style>
<template>
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
class="my-custom-class"
header="Example header"
sub-header="Example subheader"
:buttons="actionSheetButtons"
></ion-action-sheet>
</template>
<script setup lang="ts">
import { IonActionSheet, IonButton } from '@ionic/vue';
const actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
</script>
CSS Custom Properties
정의된 CSS Custom Properties 중 어느 것이든 개별 요소를 타겟할 필요 없이 Action Sheet를 스타일링하는 데 사용할 수 있어요.
JavaScript
<style>
ion-action-sheet.my-custom-class {
--background: #f58840;
--backdrop-opacity: 0.6;
--button-background-selected: #e97223;
--button-color: #000000;
--color: #fff;
/* role: "destructive" button iOS styling override */
--ion-color-danger: #000000;
}
</style>
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
class="my-custom-class"
header="Example header"
sub-header="Example subheader"
></ion-action-sheet>
<script>
var actionSheet = document.querySelector('ion-action-sheet');
actionSheet.buttons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
</script>
Angular
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonActionSheet, IonButton } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['./example.component.css'],
imports: [IonActionSheet, IonButton],
})
export class ExampleComponent {
public actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
constructor() {}
}
src/app/example.component.html
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
class="my-custom-class"
header="Example header"
subHeader="Example subheader"
[buttons]="actionSheetButtons"
></ion-action-sheet>
src/global.css
/* Note: These styles should be located in your global stylesheet */
ion-action-sheet.my-custom-class {
--background: #f58840;
--backdrop-opacity: 0.6;
--button-background-selected: #e97223;
--button-color: #000000;
--color: #fff;
/* role: "destructive" button iOS styling override */
--ion-color-danger: #000000;
}
React
src/main.tsx
import React from 'react';
import { IonActionSheet, IonButton } from '@ionic/react';
import './main.css';
function Example() {
return (
<>
<IonButton id="open-action-sheet">Open</IonButton>
<IonActionSheet
trigger="open-action-sheet"
className="my-custom-class"
header="Example header"
subHeader="Example subheader"
buttons={[
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
]}
></IonActionSheet>
</>
);
}
export default Example;
src/main.css
ion-action-sheet.my-custom-class {
--background: #f58840;
--backdrop-opacity: 0.6;
--button-background-selected: #e97223;
--button-color: #000000;
--color: #fff;
/* role: "destructive" button iOS styling override */
--ion-color-danger: #000000;
}
Vue
<style>
ion-action-sheet.my-custom-class {
--background: #f58840;
--backdrop-opacity: 0.6;
--button-background-selected: #e97223;
--button-color: #000000;
--color: #fff;
/* role: "destructive" button iOS styling override */
--ion-color-danger: #000000;
}
</style>
<template>
<ion-button id="open-action-sheet">Open</ion-button>
<ion-action-sheet
trigger="open-action-sheet"
class="my-custom-class"
header="Example header"
sub-header="Example subheader"
:buttons="actionSheetButtons"
></ion-action-sheet>
</template>
<script setup lang="ts">
import { IonActionSheet, IonButton } from '@ionic/vue';
const actionSheetButtons = [
{
text: 'Delete',
role: 'destructive',
data: {
action: 'delete',
},
},
{
text: 'Share',
data: {
action: 'share',
},
},
{
text: 'Cancel',
role: 'cancel',
data: {
action: 'cancel',
},
},
];
</script>
Accessibility
Screen Readers
Action Sheet는 스크린 리더가 접근할 수 있도록 aria 프로퍼티를 설정해요. 하지만 이 프로퍼티가 충분히 설명적이지 않거나 앱에서 사용되는 방식과 맞지 않으면 덮어쓸 수 있어요.
Role
Action Sheet에는 dialog의 role이 부여돼요. ARIA 스펙에 맞추려면 aria-label 또는 aria-labelledby 속성을 반드시 설정해야 해요.
Action Sheet Description
모든 Action Sheet에 header 프로퍼티를 정의하는 것을 강력히 권장해요. Ionic이 자동으로 aria-labelledby를 헤더 요소를 가리키도록 설정하기 때문이에요. 하지만 header를 포함하지 않기로 선택했다면, htmlAttributes 프로퍼티를 사용해 설명적인 aria-label을 제공하거나 커스텀 aria-labelledby 값을 설정하는 대안이 있어요.
Angular
const actionSheet = await this.actionSheetController.create({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});
Javascript
const actionSheet = await this.actionSheetController.create({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});
React
useIonActionSheet({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});
Vue
const actionSheet = await actionSheetController.create({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});
Action Sheet Buttons Description
텍스트가 포함된 버튼은 스크린 리더가 읽어 줘요. 버튼에 아이콘만 있거나, 기존 텍스트 외의 설명이 필요하다면 버튼의 htmlAttributes 프로퍼티에 aria-label을 전달해 레이블을 할당해야 해요.
Angular
const actionSheet = await this.actionSheetController.create({
header: 'Header',
buttons: [
{
icon: 'close',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
Javascript
const actionSheet = await this.actionSheetController.create({
header: 'Header',
buttons: [
{
icon: 'close',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
React
useIonActionSheet({
header: 'Header',
buttons: [
{
icon: 'close',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
Vue
const actionSheet = await actionSheetController.create({
header: 'Header',
buttons: [
{
icon: 'close',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
Interfaces
ActionSheetButton
interface ActionSheetButton<T = any> {
text?: string;
role?: 'cancel' | 'destructive' | 'selected' | string;
icon?: string;
cssClass?: string | string[];
id?: string;
htmlAttributes?: { [key: string]: any };
handler?: () => boolean | void | Promise<boolean | void>;
data?: T;
}
ActionSheetOptions
interface ActionSheetOptions {
header?: string;
subHeader?: string;
cssClass?: string | string[];
buttons: (ActionSheetButton | string)[];
backdropDismiss?: boolean;
translucent?: boolean;
animated?: boolean;
mode?: Mode;
keyboardClose?: boolean;
id?: string;
htmlAttributes?: { [key: string]: any };
enterAnimation?: AnimationBuilder;
leaveAnimation?: AnimationBuilder;
}
Properties
animated
Description: If true, the action sheet will animate.
Attribute: animated
Type: boolean
Default: true
backdropDismiss
Description: If true, the action sheet will be dismissed when the backdrop is clicked.
Attribute: backdrop-dismiss
Type: boolean
Default: true
buttons
Description: An array of buttons for the action sheet.
Attribute: undefined
Type: (string | ActionSheetButton<any>)[]
Default: []
cssClass
Description: Additional classes to apply for custom CSS. If multiple classes are provided they should be separated by spaces.
Attribute: css-class
Type: string | string[] | undefined
Default: undefined
enterAnimation
Description: Animation to use when the action sheet is presented.
Attribute: undefined
Type: ((baseEl: any, opts?: any) => Animation) | undefined
Default: undefined
header
Description: Title for the action sheet.
Attribute: header
Type: string | undefined
Default: undefined
htmlAttributes
Description: Additional attributes to pass to the action sheet.
Attribute: undefined
Type: undefined | { [key: string]: any; }
Default: undefined
isOpen
Description: If true, the action sheet will open. If false, the action sheet will close. Use this if you need finer grained control over presentation, otherwise just use the actionSheetController or the trigger property. Note: isOpen will not automatically be set back to false when the action sheet dismisses. You will need to do that in your code.
Attribute: is-open
Type: boolean
Default: false
keyboardClose
Description: If true, the keyboard will be automatically dismissed when the overlay is presented.
Attribute: keyboard-close
Type: boolean
Default: true
leaveAnimation
Description: Animation to use when the action sheet is dismissed.
Attribute: undefined
Type: ((baseEl: any, opts?: any) => Animation) | undefined
Default: undefined
mode
Description: The mode determines which platform styles to use. This is a virtual property that is set once during initialization and will not update if you change its value after the initial render.
Attribute: mode
Type: "ios" | "md"
Default: undefined
subHeader
Description: Subtitle for the action sheet.
Attribute: sub-header
Type: string | undefined
Default: undefined
translucent
Description: If true, the action sheet will be translucent. Only applies when the mode is "ios" and the device supports backdrop-filter.
Attribute: translucent
Type: boolean
Default: false
trigger
Description: An ID corresponding to the trigger element that causes the action sheet to open when clicked.
Attribute: trigger
Type: string | undefined
Default: undefined
Events
| Name | Description | Bubbles |
|---|---|---|
didDismiss |
Emitted after the action sheet has dismissed. Shorthand for ionActionSheetDidDismiss. | true |
didPresent |
Emitted after the action sheet has presented. Shorthand for ionActionSheetWillDismiss. | true |
ionActionSheetDidDismiss |
Emitted after the action sheet has dismissed. | true |
ionActionSheetDidPresent |
Emitted after the action sheet has presented. | true |
ionActionSheetWillDismiss |
Emitted before the action sheet has dismissed. | true |
ionActionSheetWillPresent |
Emitted before the action sheet has presented. | true |
willDismiss |
Emitted before the action sheet has dismissed. Shorthand for ionActionSheetWillDismiss. | true |
willPresent |
Emitted before the action sheet has presented. Shorthand for ionActionSheetWillPresent. | true |
Methods
dismiss
Description: Dismiss the action sheet overlay after it has been presented. This is a no-op if the overlay has not been presented yet. If you want to remove an overlay from the DOM that was never presented, use the remove method.
Signature: dismiss(data?: any, role?: string) => Promise<boolean>
Parameters: data: Any data to emit in the dismiss events. role: The role of the element that is dismissing the action sheet. This can be useful in a button handler for determining which button was clicked to dismiss the action sheet. Some examples include: "cancel", "destructive", "selected", and "backdrop".
onDidDismiss
Description: Returns a promise that resolves when the action sheet did dismiss.
Signature: onDidDismiss<T = any>() => Promise<OverlayEventDetail<T>>
onWillDismiss
Description: Returns a promise that resolves when the action sheet will dismiss.
Signature: onWillDismiss<T = any>() => Promise<OverlayEventDetail<T>>
present
Description: Present the action sheet overlay after it has been created.
Signature: present() => Promise<void>
CSS Shadow Parts
No CSS shadow parts available for this component.
CSS Custom Properties
iOS
| Name | Description |
|---|---|
--backdrop-opacity |
Opacity of the backdrop |
--background |
Background of the action sheet group |
--button-background |
Background of the action sheet button |
--button-background-activated |
Background of the action sheet button when pressed. Note: setting this will interfere with the Material Design ripple. |
--button-background-activated-opacity |
Opacity of the action sheet button background when pressed |
--button-background-focused |
Background of the action sheet button when tabbed to |
--button-background-focused-opacity |
Opacity of the action sheet button background when tabbed to |
--button-background-hover |
Background of the action sheet button on hover |
--button-background-hover-opacity |
Opacity of the action sheet button background on hover |
--button-background-selected |
Background of the selected action sheet button |
--button-background-selected-opacity |
Opacity of the selected action sheet button background |
--button-color |
Color of the action sheet button |
--button-color-activated |
Color of the action sheet button when pressed |
--button-color-disabled |
Color of the selected action sheet button when disabled |
--button-color-focused |
Color of the action sheet button when tabbed to |
--button-color-hover |
Color of the action sheet button on hover |
--button-color-selected |
Color of the selected action sheet button |
--color |
Color of the action sheet text |
--height |
height of the action sheet |
--max-height |
Maximum height of the action sheet |
--max-width |
Maximum width of the action sheet |
--min-height |
Minimum height of the action sheet |
--min-width |
Minimum width of the action sheet |
--width |
Width of the action sheet |
MD
| Name | Description |
|---|---|
--backdrop-opacity |
Opacity of the backdrop |
--background |
Background of the action sheet group |
--button-background |
Background of the action sheet button |
--button-background-activated |
Background of the action sheet button when pressed. Note: setting this will interfere with the Material Design ripple. |
--button-background-activated-opacity |
Opacity of the action sheet button background when pressed |
--button-background-focused |
Background of the action sheet button when tabbed to |
--button-background-focused-opacity |
Opacity of the action sheet button background when tabbed to |
--button-background-hover |
Background of the action sheet button on hover |
--button-background-hover-opacity |
Opacity of the action sheet button background on hover |
--button-background-selected |
Background of the selected action sheet button |
--button-background-selected-opacity |
Opacity of the selected action sheet button background |
--button-color |
Color of the action sheet button |
--button-color-activated |
Color of the action sheet button when pressed |
--button-color-disabled |
Color of the selected action sheet button when disabled |
--button-color-focused |
Color of the action sheet button when tabbed to |
--button-color-hover |
Color of the action sheet button on hover |
--button-color-selected |
Color of the selected action sheet button |
--color |
Color of the action sheet text |
--height |
height of the action sheet |
--max-height |
Maximum height of the action sheet |
--max-width |
Maximum width of the action sheet |
--min-height |
Minimum height of the action sheet |
--min-width |
Minimum width of the action sheet |
--width |
Width of the action sheet |
Slots
No slots available for this component.
더 알아보기 (Learn more)
ion-action-sheet는 옵션 목록을 바닥에서 올라오는 시트 형태로 보여 주는 다이얼로그예요. 템플릿에 직접 넣고 trigger나 isOpen으로 표시하거나, actionSheetController로 세밀하게 제어할 수 있어요. 버튼의 role과 닫힐 때의 data/role 정보를 활용해 상호작용 결과를 처리하세요.