Skip to main content

ion-action-sheet

scoped

Action Sheet は複数の選択肢を表示するダイアログです。アプリのコンテンツに重なって表示され、ユーザーは閉じるまでアプリの操作を再開できません。ios モードでは破壊的な操作の選択肢が強調表示されます。背景をタップする、デスクトップで Escape キーを押すなどの方法で閉じられます。

ion-action-sheet はテンプレートに直接記述できます。これにより、Action Sheet を表示するために登録するハンドラを減らせます。

isOpen を使う​

ion-action-sheet の isOpen プロパティを使うと、アプリの状態に応じて Action Sheet の表示を制御できます。isOpen を true にすると Action Sheet が開き、isOpen を false にすると閉じます。

isOpen は一方向のデータバインディングを使うため、Action Sheet を閉じても自動的に false には戻りません。ionActionSheetDidDismiss または didDismiss イベントを受け取ったときに、isOpen を false に設定してください。これにより、ion-action-sheet の内部実装がアプリの状態に強く依存するのを防げます。一方向のバインディングなら、Action Sheet は reactive 変数が返す boolean 値だけを扱います。双方向の場合は、その値に加えて変数自体の有無も扱う必要があり、動作が予測しづらく、デバッグが難しくなることがあります。

Controller Action Sheets​

Action Sheet の表示・非表示をより細かく制御したい場合は、actionSheetControllerを使用することができます。

Buttons​

ボタンの role プロパティには destructive または cancel を指定できます。role を指定しないボタンは、そのプラットフォームの標準の外観になります。cancel のボタンは配列内の位置にかかわらず一番下に表示され、それ以外のボタンは buttons 配列に追加された順に並びます。destructive のボタンは、一番上に表示されるよう配列の先頭に置くことを推奨します。背景をタップして Action Sheet を閉じると、cancel のボタンのハンドラが呼び出されます。

Buttonは ActionSheetButton の data プロパティを介してデータを渡すこともできます。これは onDidDismiss メソッドの戻り値にある data フィールドにデータを入力します。

Collecting Role Information on Dismiss​

didDismiss イベントの発生時に、イベント詳細の data と role フィールドから、Action Sheet がどのように閉じられたかを確認できます。

Console
Console messages will appear here when logged from the example above.

テーマ​

アクションシートは scoped encapsulation を採用しており、実行時に各スタイルにクラスを追加することで、自動的にCSSをスコープ化します。CSSでscoped selector をオーバーライドするには、higher specificity selector が必要です。

スタイリング​

私たちは、 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;
}

CSS Custom Properties​

CSS Custom Properties は、個々の要素を対象とすることなく、Action Sheet のスタイルに使用することができます。

アクセシビリティ​

Screen Readers​

アクションシートは、スクリーンリーダーにとって アクセシブル であるためにariaプロパティを設定しますが、これらのプロパティは、十分な説明になっていなかったり、アクションシートがアプリでどのように使用されているかに合っていなかったりする場合、オーバーライドすることができます。

Role​

アクションシートには role として dialog が設定されます。ARIA仕様に合わせるためには、aria-label属性かaria-labelledby属性のどちらかを設定しなければなりません。

Action Sheet の読み上げ用説明​

Ionicは自動的にヘッダー要素を指すように aria-labelledby を設定するので、すべてのアクションシートには header プロパティを定義することを強く推奨します。しかし、headerを含めない場合は、htmlAttributesプロパティを使って、説明的なaria-labelを指定するか、カスタムのaria-labelledby値を設定することもできます。

const actionSheet = await this.actionSheetController.create({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});

Action Sheet のボタンの読み上げ用説明​

テキストを含むボタンはスクリーンリーダーによって読み取られる。ボタンがアイコンのみを含んでいる場合や、既存のテキスト以外の説明が必要な場合は、ボタンの htmlAttributes プロパティに aria-label を渡して、ラベルをボタンに割り当てる必要があります。

const actionSheet = await this.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​

Descriptiontrueの場合、アクションシートはアニメーションを行います。
Attributeanimated
Typeboolean
Defaulttrue

backdropDismiss​

Descriptiontrueの場合、バックドロップがクリックされるとアクションシートが解除されます。
Attributebackdrop-dismiss
Typeboolean
Defaulttrue

buttons​

Descriptionアクションシートのボタンの配列です。
Attributeundefined
Type(string | ActionSheetButton<any>)[]
Default[]

cssClass​

DescriptionカスタムCSSに適用する追加のクラス。複数のクラスを指定する場合は、スペースで区切る必要があります。
Attributecss-class
Typestring | string[] | undefined
Defaultundefined

enterAnimation​

Descriptionアクションシートの提示時に使用するアニメーションです。
Attributeundefined
Type((baseEl: any, opts?: any) => Animation) | undefined
Defaultundefined

header​

Descriptionアクションシートのタイトルです。
Attributeheader
Typestring | undefined
Defaultundefined

htmlAttributes​

Descriptionアクションシートに渡す追加属性。
Attributeundefined
Typeundefined | { [key: string]: any; }
Defaultundefined

isOpen​

Descriptiontrueの場合、アクションシートは開かれます。falseの場合、アクションシートは閉じます。プレゼンテーションの細かな制御が必要な場合はこれを使用し、そうでない場合は actionSheetController または trigger プロパティを使用します。注意: アクションシートが終了しても、isOpenは自動的にfalseに戻されません。あなたのコードでそれを行う必要があります。
Attributeis-open
Typeboolean
Defaultfalse

keyboardClose​

Descriptiontrueの場合、オーバーレイが表示されたときにキーボードが自動的に解除されます。
Attributekeyboard-close
Typeboolean
Defaulttrue

leaveAnimation​

Descriptionアクションシートが解除されたときに使用するアニメーションです。
Attributeundefined
Type((baseEl: any, opts?: any) => Animation) | undefined
Defaultundefined

mode​

Descriptionmodeは、どのプラットフォームのスタイルを使用するかを決定します。

This is a virtual property that is set once during initialization and will not update if you change its value after the initial render.
Attributemode
Type"ios" | "md"
Defaultundefined

subHeader​

Descriptionアクションシートのサブタイトルです。
Attributesub-header
Typestring | undefined
Defaultundefined

translucent​

Descriptiontrueの場合、アクションシートは半透明になります。modeが "ios" で、デバイスが backdrop-filter をサポートしている場合にのみ適用されます。
Attributetranslucent
Typeboolean
Defaultfalse

trigger​

Descriptionクリックするとアクションシートが開くトリガー要素に対応するID。
Attributetrigger
Typestring | undefined
Defaultundefined

Events​

NameDescriptionBubbles
didDismissアクションシートが解散した後に発行されます。ionActionSheetDidDismissの略記。true
didPresentアクションシートが提示された後に発行されます。ionActionSheetWillDismissの略語。true
ionActionSheetDidDismissアクションシートが解散した後に発行されます。true
ionActionSheetDidPresentアクションシートが提示された後に発行されます。true
ionActionSheetWillDismissアクションシートが解散する前に発行されます。true
ionActionSheetWillPresentアクションシートが提示される前に発行されます。true
willDismissアクションシートが解散する前に発行されます。ionActionSheetWillDismissの略記。true
willPresentアクションシートが提示される前に発行されます。ionActionSheetWillPresentの略記。true

Methods​

dismiss​

Descriptionアクションシートのオーバーレイが表示された後に閉じます。オーバーレイがまだ表示されていない場合は何もしません。表示されなかったオーバーレイを DOM から削除するには、remove メソッドを使用してください。
Signaturedismiss(data?: any, role?: string) => Promise<boolean>
Parametersdata: 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アクションシートが解散したときに解決するPromiseを返します。
SignatureonDidDismiss<T = any>() => Promise<OverlayEventDetail<T>>

onWillDismiss​

Descriptionアクションシートが解散するタイミングを解決するPromiseを返します。
SignatureonWillDismiss<T = any>() => Promise<OverlayEventDetail<T>>

present​

Descriptionアクションシートのオーバーレイを作成後に提示します。
Signaturepresent() => Promise<void>

CSS Shadow Parts​

No CSS shadow parts available for this component.

CSS Custom Properties​

NameDescription
--backdrop-opacity背景の不透明度
--backgroundアクションシートグループの背景
--button-backgroundアクションシートボタンの背景
--button-background-activatedアクションシートボタンが押されたときの背景。注意:これを設定すると、Material Designの波紋に干渉します。
--button-background-activated-opacityアクションシートボタンが押されたときの背景の不透明度
--button-background-focusedタブで移動したときのアクションシートボタンの背景。
--button-background-focused-opacityタブで移動したときのアクションシートボタンの背景の不透明度。
--button-background-hoverホバー時のアクションシートボタンの背景
--button-background-hover-opacityホバー時のアクションシートボタンの背景の不透明度
--button-background-selected選択したアクションシートボタンの背景
--button-background-selected-opacity選択されたアクションシートボタンの背景の不透明度
--button-colorアクションシートボタンの色
--button-color-activatedアクションシートボタンが押されたときの色
--button-color-disabled無効時の選択されたアクション・シート・ボタンの色
--button-color-focusedタブで移動したときのアクションシートのボタンの色。
--button-color-hoverホバー時のアクションシートボタンの色
--button-color-selected選択されたアクションシートのボタンの色
--colorアクションシートテキストの色
--heightアクションシートの高さ
--max-heightアクションシートの最大の高さ
--max-widthアクションシートの最大幅
--min-heightアクションシートの最小高さ
--min-widthアクションシートの最小幅
--widthアクションシートの横幅

Slots​

No slots available for this component.