scoped
Action Sheet は複数の選択肢を表示するダイアログです。アプリのコンテンツに重なって表示され、ユーザーは閉じるまでアプリの操作を再開できません。ios モードでは破壊的な操作の選択肢が強調表示されます。背景をタップする、デスクトップで Escape キーを押すなどの方法で閉じられます。
ion-action-sheet はテンプレートに直接記述できます。これにより、Action Sheet を表示するために登録するハンドラを減らせます。
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 値だけを扱います。双方向の場合は、その値に加えて変数自体の有無も扱う必要があり、動作が予測しづらく、デバッグが難しくなることがあります。
Action Sheet の表示・非表示をより細かく制御したい場合は、actionSheetControllerを使用することができます。
ボタンの role プロパティには destructive または cancel を指定できます。role を指定しないボタンは、そのプラットフォームの標準の外観になります。cancel のボタンは配列内の位置にかかわらず一番下に表示され、それ以外のボタンは buttons 配列に追加された順に並びます。destructive のボタンは、一番上に表示されるよう配列の先頭に置くことを推奨します。背景をタップして Action Sheet を閉じると、cancel のボタンのハンドラが呼び出されます。
Buttonは ActionSheetButton の data プロパティを介してデータを渡すこともできます。これは onDidDismiss メソッドの戻り値にある data フィールドにデータを入力します。
didDismiss イベントの発生時に、イベント詳細の data と role フィールドから、Action Sheet がどのように閉じられたかを確認できます。
Console messages will appear here when logged from the example above.
アクションシートは scoped encapsulation を採用しており、実行時に各スタイルにクラスを追加することで、自動的にCSSをスコープ化します。CSSでscoped selector をオーバーライドするには、higher specificity selector が必要です。
私たちは、 create メソッドで cssClass にカスタムクラスを渡し、それを使ってホストと内部要素にカスタムスタイルを追加することをお勧めします。このプロパティは、スペースで区切られた複数のクラスを受け付けることもできます。
.action-sheet-group {
background: #e5e5e5;
}
.my-custom-class .action-sheet-group {
background: #e5e5e5;
}
CSS Custom Properties は、個々の要素を対象とすることなく、Action Sheet のスタイルに使用することができます。
アクションシートは、スクリーンリーダーにとって アクセシブル であるためにariaプロパティを設定しますが、これらのプロパティは、十分な説明になっていなかったり、アクションシートがアプリでどのように使用されているかに合っていなかったりする場合、オーバーライドすることができます。
アクションシートには role として dialog が設定されます。ARIA仕様に合わせるためには、aria-label属性かaria-labelledby属性のどちらかを設定しなければなりません。
Ionicは自動的にヘッダー要素を指すように aria-labelledby を設定するので、すべてのアクションシートには header プロパティを定義することを強く推奨します。しかし、headerを含めない場合は、htmlAttributesプロパティを使って、説明的なaria-labelを指定するか、カスタムのaria-labelledby値を設定することもできます。
- Angular
- Javascript
- React
- Vue
const actionSheet = await this.actionSheetController.create({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});
const actionSheet = await this.actionSheetController.create({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});
useIonActionSheet({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});
const actionSheet = await actionSheetController.create({
htmlAttributes: {
'aria-label': 'action sheet dialog',
},
});
テキストを含むボタンはスクリーンリーダーによって読み取られる。ボタンがアイコンのみを含んでいる場合や、既存のテキスト以外の説明が必要な場合は、ボタンの htmlAttributes プロパティに aria-label を渡して、ラベルをボタンに割り当てる必要があります。
- Angular
- Javascript
- React
- Vue
const actionSheet = await this.actionSheetController.create({
header: 'Header',
buttons: [
{
icon: 'close',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
const actionSheet = await this.actionSheetController.create({
header: 'Header',
buttons: [
{
icon: 'close',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
useIonActionSheet({
header: 'Header',
buttons: [
{
icon: 'close',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
const actionSheet = await actionSheetController.create({
header: 'Header',
buttons: [
{
icon: 'close',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
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;
}
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;
}
| Description | trueの場合、アクションシートはアニメーションを行います。 |
| Attribute | animated |
| Type | boolean |
| Default | true |
| Description | trueの場合、バックドロップがクリックされるとアクションシートが解除されます。 |
| Attribute | backdrop-dismiss |
| Type | boolean |
| Default | true |
| Description | アクションシートのボタンの配列です。 |
| Attribute | undefined |
| Type | (string | ActionSheetButton<any>)[] |
| Default | [] |
| Description | カスタムCSSに適用する追加のクラス。複数のクラスを指定する場合は、スペースで区切る必要があります。 |
| Attribute | css-class |
| Type | string | string[] | undefined |
| Default | undefined |
| Description | アクションシートの提示時に使用するアニメーションです。 |
| Attribute | undefined |
| Type | ((baseEl: any, opts?: any) => Animation) | undefined |
| Default | undefined |
| Description | アクションシートのタイトルです。 |
| Attribute | header |
| Type | string | undefined |
| Default | undefined |
| Description | アクションシートに渡す追加属性。 |
| Attribute | undefined |
| Type | undefined | { [key: string]: any; } |
| Default | undefined |
| Description | trueの場合、アクションシートは開かれます。falseの場合、アクションシートは閉じます。プレゼンテーションの細かな制御が必要な場合はこれを使用し、そうでない場合は actionSheetController または trigger プロパティを使用します。注意: アクションシートが終了しても、isOpenは自動的にfalseに戻されません。あなたのコードでそれを行う必要があります。 |
| Attribute | is-open |
| Type | boolean |
| Default | false |
| Description | trueの場合、オーバーレイが表示されたときにキーボードが自動的に解除されます。 |
| Attribute | keyboard-close |
| Type | boolean |
| Default | true |
| Description | アクションシートが解除されたときに使用するアニメーションです。 |
| Attribute | undefined |
| Type | ((baseEl: any, opts?: any) => Animation) | undefined |
| Default | undefined |
| Description | modeは、どのプラットフォームのスタイルを使用するかを決定します。
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 |
| Description | アクションシートのサブタイトルです。 |
| Attribute | sub-header |
| Type | string | undefined |
| Default | undefined |
| Description | trueの場合、アクションシートは半透明になります。modeが "ios" で、デバイスが backdrop-filter をサポートしている場合にのみ適用されます。 |
| Attribute | translucent |
| Type | boolean |
| Default | false |
| Description | クリックするとアクションシートが開くトリガー要素に対応するID。 |
| Attribute | trigger |
| Type | string | undefined |
| Default | undefined |
| Name | Description | Bubbles |
|---|
didDismiss | アクションシートが解散した後に発行されます。ionActionSheetDidDismissの略記。 | true |
didPresent | アクションシートが提示された後に発行されます。ionActionSheetWillDismissの略語。 | true |
ionActionSheetDidDismiss | アクションシートが解散した後に発行されます。 | true |
ionActionSheetDidPresent | アクションシートが提示された後に発行されます。 | true |
ionActionSheetWillDismiss | アクションシートが解散する前に発行されます。 | true |
ionActionSheetWillPresent | アクションシートが提示される前に発行されます。 | true |
willDismiss | アクションシートが解散する前に発行されます。ionActionSheetWillDismissの略記。 | true |
willPresent | アクションシートが提示される前に発行されます。ionActionSheetWillPresentの略記。 | true |
| Description | アクションシートのオーバーレイが表示された後に閉じます。オーバーレイがまだ表示されていない場合は何もしません。表示されなかったオーバーレイを DOM から削除するには、remove メソッドを使用してください。 |
| 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". |
| Description | アクションシートが解散したときに解決するPromiseを返します。 |
| Signature | onDidDismiss<T = any>() => Promise<OverlayEventDetail<T>> |
| Description | アクションシートが解散するタイミングを解決するPromiseを返します。 |
| Signature | onWillDismiss<T = any>() => Promise<OverlayEventDetail<T>> |
| Description | アクションシートのオーバーレイを作成後に提示します。 |
| Signature | present() => Promise<void> |
No CSS shadow parts available for this component.
| Name | Description |
|---|
--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 | アクションシートの横幅 |
| Name | Description |
|---|
--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 | アクションシートの横幅 |
No slots available for this component.