scoped
アラートは、ユーザーに情報を提示したり、Inputを使ってユーザーから情報を収集したりするダイアログである。アラートはアプリのコンテンツの上に表示され、アプリとの対話を再開する前に、ユーザーが手動で解除する必要があります。また、オプションで header、subHeader、message を持つことができます。
ion-alert は、テンプレートに直接コ ンポーネントを記述して使用することができます。これにより、アラートを表示するために必要なハンドラの数を減らすことができます。
ion-alert の isOpen プロパティは、開発者がアプリケーションの状態からアラートの表示状態を制御することを可能にします。つまり、isOpen を true に設定するとアラートが表示され、isOpen を false に設定するとアラートは解除されます。
isOpen は一方通行のデータバインディングを使用しているため、アラートが解除されたときに自動的に false に設定されることはありません。開発者は ionAlertDidDismiss または didDismiss イベントを待ち、isOpen を false に設定する必要があります。この理由は、ion-alert の内部がアプリケーションの状態と密接に結合するのを防ぐためである。一方通行のデータバインディングでは、アラートはリアクティブ変数が提供するブーリアン値だけを気にすればよい。双方向のデータバインディングでは、アラートはブーリアン値とリアクティブ変数の存在の両方に関心を持つ必要があります。これは、非決定的な動作につながり、アプリケーションのデバッグを困難にする可能性があります。
alertControllerは、アラートを表示するタイミングや解除するタイミングをより細かく制御する必要がある場合に使用することができる。
buttons の配列には、各buttonの text のプロパティと、オプションで handler を利用することができます。 handler が false を返した場合、buttonがクリックされてもAlertは自動的に解除されません。すべての buttons は、左から右にボタン配列に追加された順序で表示されます。 Note: 一番右のボタン(配列の最後の1つ)がメインボタンです。
オプションで、cancelのような role プロパティをボタンに追加することができます。もし cancel ロールがボタンのいずれかに設定されている場合、バックドロップをタップしてアラートが解除されると、キャンセルロールを持つボタンから handler が起動されます。
Console messages will appear here when logged from the example above.
Alertには、複数の異なるInputを含めることもでき、そのデータをアプリで受け取ることができます。 Inputはユーザーに情報の入力を促す簡単な方法として使用できます。Radios, checkboxes と text inputs textarea はすべて利用できますが、これらを混ぜて利用することはできません。例えば、Alertはすべてbutton Inputであったり、すべてcheckboxでのInputを持つことはできますが、同一のAlertにradioとcheckbox Inputを混ぜることはできません。ただし、"text" Inputでは、 url, email, text などの複数のtypeを混ぜて利用することはできます。アラートのガイドラインに収まらない複雑なForm UIが必要な場合は、代わりにModal内でFormを構築することをお勧めします。
Alertはscopedによるカプセル化を使用しており、実行時に各スタイルにクラスを追加することで自動的にCSSをスコープします。CSSでscopedセレクタをオーバーライドするには、higher specificity セレクタが必要です。
create メソッドで cssClass にカスタムクラスを渡し、それを使ってホストと内部要素にカスタムスタイルを追加することをお勧めします。このプロパティは、スペースで区切られた複数のクラスを受け付けることもできます。
.alert-wrapper {
background: #e5e5e5;
}
.my-custom-class .alert-wrapper {
background: #e5e5e5;
}
CSSカスタムプロパティ は、個々の要素をターゲットにすることなく、アラートのスタイルに使用することができます。
.my-custom-class {
--background: #e5e5e5;
}
IonicのAngularアプリを構築する場合、スタイルはグローバルなスタイルシートファイルに追加する必要があります。
アラートは、スクリーンリーダーにとってアクセシブルであるために、ariaプロパティを設定しますが、これらのプロパティは、十分な説明がない場合、またはアラートがアプリでどのように使用されているかと一致しない場合は、オーバーライドすることができます。
Ionicは自動的にアラートのroleを、入力やボタンがある場合はalertdialogに、何もない場合はalertに設定します。
アラートに header プロパティが定義されている場合、aria-labelledby 属性は自動的にヘッダの ID に設定されます。 header が定義されていない場合、subHeader 要素がフォールバックとして使用されます。同様に、 aria-describedby 属性が定義されている場合は、自動的に message 要素の ID が設定されます。
ARIAの仕様に合わせるために、アラートには message と header または subHeader を含めることを強くお勧めします。もし header や subHeader を含めない場合は、htmlAttributes プロパティを使用して、説明的な aria-label を指定することができます。
- Angular
- Javascript
- React
- Vue
const alert = await this.alertController.create({
message: 'This is an alert with custom aria attributes.',
htmlAttributes: {
'aria-label': 'alert dialog',
},
});
const alert = await this.alertController.create({
message: 'This is an alert with custom aria attributes.',
htmlAttributes: {
'aria-label': 'alert dialog',
},
});
useIonAlert({
message: 'This is an alert with custom aria attributes.',
htmlAttributes: {
'aria-label': 'alert dialog',
},
});
const alert = await alertController.create({
message: 'This is an alert with custom aria attributes.',
htmlAttributes: {
'aria-label': 'alert dialog',
},
});
すべてのARIA属性は、アラートのhtmlAttributesプロパティにカスタム値を定義することで、手動で上書きすることができます。
Buttons containing text will be read by a screen reader. If a description other than the existing text is desired, a label can be set on the button by passing aria-label to the htmlAttributes property on the button.
- Angular
- Javascript
- React
- Vue
const alert = await this.alertController.create({
header: 'Header',
buttons: [
{
text: 'Exit',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
const alert = await this.alertController.create({
header: 'Header',
buttons: [
{
text: 'Exit',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
useIonAlert({
header: 'Header',
buttons: [
{
text: 'Exit',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
const alert = await alertController.create({
header: 'Header',
buttons: [
{
text: 'Exit',
htmlAttributes: {
'aria-label': 'close',
},
},
],
});
type AlertButtonOverlayHandler = boolean | void | { [key: string]: any };
interface AlertButton {
text: string;
role?: 'cancel' | 'destructive' | string;
cssClass?: string | string[];
id?: string;
htmlAttributes?: { [key: string]: any };
handler?: (value: any) => AlertButtonOverlayHandler | Promise<AlertButtonOverlayHandler>;
}
interface AlertInput {
type?: TextFieldTypes | 'checkbox' | 'radio' | 'textarea';
name?: string;
placeholder?: string;
value?: any;
label?: string;
checked?: boolean;
disabled?: boolean;
id?: string;
handler?: (input: AlertInput) => void;
min?: string | number;
max?: string | number;
cssClass?: string | string[];
attributes?: { [key: string]: any };
tabindex?: number;
}
interface AlertOptions {
header?: string;
subHeader?: string;
message?: string | IonicSafeString;
cssClass?: string | string[];
inputs?: AlertInput[];
buttons?: (AlertButton | string)[];
backdropDismiss?: boolean;
translucent?: boolean;
animated?: boolean;
htmlAttributes?: { [key: string]: any };
mode?: Mode;
keyboardClose?: boolean;
id?: string;
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 | AlertButton)[] |
| 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 | アラートに表示するInputの配列。 |
| Attribute | undefined |
| Type | AlertInput[] |
| Default | [] |
| Description | trueの場合、アラートは開く。もし false ならば、アラートは閉じます。alertControllerや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 | アラートに表示されるメインメッセージ。messageには、文字列としてプレーンテキストまたはHTMLのいずれかを指定することができます。通常HTML用に予約されている文字を表示するには、エスケープする必要があります。例えば、<Ionic>は <Ionic> になります:セキュリティ・ドキュメント このプロパティは、カスタムHTMLを文字列として受け付けます。デフォルトでは、コンテンツはプレーンテキストとしてパースされます。カスタムHTMLを使用するには、Ionicの設定で innerHTMLTemplatesEnabled を true に設定する必要があります。 |
| Attribute | message |
| Type | IonicSafeString | string | undefined |
| Default | undefined |
| Description | modeは、どのプラットフォームのスタイルを使用するかを決定します。 |
| 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 |
|---|
didDismiss | アラートが解除された後に発行されます。ionAlertDidDismissの略記。 |
didPresent | アラートが提示された後に発行されます。ionAlertWillDismissの略記。 |
ionAlertDidDismiss | アラートが解除された後に発行されます。 |
ionAlertDidPresent | アラートが提示された後に発行されます。 |
ionAlertWillDismiss | アラートが解除される前に発行されます。 |
ionAlertWillPresent | アラートが提示される前に発行されます。 |
willDismiss | アラートが解除される前に発行されます。ionAlertWillDismissの略記。 |
willPresent | アラートが提示される前に発行されます。ionAlertWillPresentの略記。 |
| Description | アラートオーバーレイが表示された後、解除します。 |
| Signature | dismiss(data?: any, role?: string) => Promise<boolean> |
| 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 | 注意喚起の背景 |
--height | アラートの高さ |
--max-height | アラートの最大の高さ |
--max-width | アラートの最大幅 |
--min-height | アラートの最小の高さ |
--min-width | アラートの最小幅 |
--width | アラートの幅 |
No slots available for this component.