shadow トーストは、最近のアプリケーションでよく使われる小さな通知です。操作に関するフィードバックを提供したり、システムメッセージを表示したりするために使用されます。トーストは、アプリケーションのコンテンツの上に表示され、アプリケーションによって解除されると、アプリケーションとの対話を再開することができます。
ion-toastは、テンプレートに直接コンポーネントを記述して使用することができます。これにより、トーストを表示するために配線する必要があるハンドラの数を減らすことができます。
ion-toast の isOpen プロパティは、開発者がアプリケーションの状態からトーストの表示状態を制御できるようにするものです。つまり、isOpen を true に設定するとトーストが表示され、isOpen を false に設定するとトーストは破棄されます。
isOpen は一方通行のデータバインディングを使用しているため、トーストが破棄されたときに自動的に false に設定されることはありません。開発者は ionToastDidDismiss または didDismiss イベントをリスニングして isOpen を false に設定する必要があります。この理由は、ion-toast の内部がアプリケーションの状態と密接に結合するのを防ぐためである。一方通行のデータバインディングでは、トーストはリアクティブ変数が提供するブーリアン値だけを気にすればよい。一方通行のデータバインディングでは、トーストはブーリアン値とリアクティブ変数の存在の両方に関心を持つ必要があります。これは、非決定的な動作につながり、アプリケーションのデバッグを困難にします。
トーストは静かな通知であり、ユーザーの邪魔をしないように意図されています。そのため、トーストを解除するためにユーザーの操作を必要とするべきではありません。
トーストは、トーストオプションの duration に表示するミリ秒数を渡すことで、特定の時間経過後に自動的に解除されるようにすることができます。もし "cancel" という役割を持つボタンが追加された場合、そのボタンがトーストを終了させます。作成後にトーストを破棄するには、インスタンスの dismiss() メソッドを呼び出してください。
ハードウェアの戻るボタンを押しても、トーストはユーザーの邪魔をしないようになっているので、トーストは破棄されません。
次の例では、buttons プロパティを使用して、クリックすると自動的にトーストを解散させるボタンを追加する方法と、解散イベントの role を収集する方法を示しています。
トーストは、ビューポートの上部、下部、中部に配置することができます。位置は作成時に渡すことができます。指定できる値は top, bottom, middle です。位置が指定されない場合、トーストはビューポートの一番下に表示されます。
トースト内のボタンコンテナは、layoutプロパティを使用して、メッセージと同じ行に表示するか、別々の行に積み重ねて表示することができます。スタックレイアウトは、長いテキスト値を持つボタンで使用する必要があります。さらに、スタックトーストレイアウトのボタンは side の値として start または end のどちらかを使用できますが、両方を使用することはできません。
トースト内のコンテンツの横にアイコンを追加することができます。一般的に、トーストのアイコンはスタイルやコンテキストを追加するために使用されるべきで、ユーザーの注意を引いたり、トーストの優先順位を上げたりするために使用すべきではありません。より優先順位の高いメッセージをユーザーに伝えたい場合や、応答を保証したい場合は、代わりに Alert を使用することをお勧めします。
Toasts are intended to be subtle notifications and are not intended to interrupt the user. User interaction should not be required to dismiss the toast. As a result, focus is not automatically moved to a toast when one is presented.
Toasts set aria properties in order to be accessible to screen readers, but these properties can be overridden if they aren't descriptive enough or don't align with how the toast is being used in an app.
ion-toast has role="status" and aria-live="polite" set on the inner .toast-content element. This causes screen readers to only announce the toast message and header. Buttons and icons will not be announced when the toast is presented.
aria-live causes screen readers to announce the content of the toast when it is updated. However, since the attribute is set to 'polite', screen readers should not interrupt the current task.
Since toasts are intended to be subtle notification, aria-live should never be set to "assertive". If developers need to interrupt the user with an important message, we recommend using an alert .
Buttons containing text will be read by a screen reader when they are interacted with. If a button contains only an icon, or a description other than the existing text is desired, a label should be assigned to the button by passing aria-label to the htmlAttributes property on the button.
Angular Javascript React Vue const toast = await this . toastController . create ( { header : 'Header' , buttons : [ { icon : 'close' , htmlAttributes : { 'aria-label' : 'close' , } , } , ] , } ) ; Copy const toast = await this . toastController . create ( { header : 'Header' , buttons : [ { icon : 'close' , htmlAttributes : { 'aria-label' : 'close' , } , } , ] , } ) ; Copy useIonToast ( { header : 'Header' , buttons : [ { icon : 'close' , htmlAttributes : { 'aria-label' : 'close' , } , } , ] , } ) ; Copy const toast = await toastController . create ( { header : 'Header' , buttons : [ { icon : 'close' , htmlAttributes : { 'aria-label' : 'close' , } , } , ] , } ) ; Copy While this is not a complete list, here are some guidelines to follow when using toasts.
Do not require user interaction to dismiss toasts. For example, having a "Dismiss" button in the toast is fine, but the toast should also automatically dismiss on its own after a timeout period. If you need user interaction for a notification, consider using an alert instead.
For toasts with long messages, consider adjusting the duration property to allow users enough time to read the content of the toast.
interface ToastButton { text ? : string ; icon ? : string ; side ? : 'start' | 'end' ; role ? : 'cancel' | string ; cssClass ? : string | string [ ] ; htmlAttributes ? : { [ key : string ] : any } ; handler ? : ( ) => boolean | void | Promise < boolean | void > ; } Copy interface ToastOptions { header ? : string ; message ? : string | IonicSafeString ; cssClass ? : string | string [ ] ; duration ? : number ; buttons ? : ( ToastButton | string ) [ ] ; position ? : 'top' | 'bottom' | 'middle' ; translucent ? : boolean ; animated ? : boolean ; icon ? : string ; htmlAttributes ? : { [ key : string ] : any } ; color ? : Color ; mode ? : Mode ; keyboardClose ? : boolean ; id ? : string ; enterAnimation ? : AnimationBuilder ; leaveAnimation ? : AnimationBuilder ; } Copy Description trueの場合、トーストはアニメーションします。Attribute animatedType booleanDefault true
Description トースト用のボタンがずらり。 Attribute undefinedType (string | ToastButton)[] | undefinedDefault undefined
Description アプリケーションのカラーパレットから使用する色を指定します。デフォルトのオプションは以下の通りです。 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", と "dark" です.色に関する詳しい情報は theming を参照してください。 Attribute colorType "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefinedDefault undefined
Description カスタムCSSに適用する追加のクラス。複数のクラスを指定する場合は、スペースで区切る必要があります。 Attribute css-classType string | string[] | undefinedDefault undefined
Description トーストを隠すまでに何ミリ秒待つかを指定します。デフォルトでは、dismiss()が呼ばれるまで表示されます。 Attribute durationType numberDefault config.getNumber('toastDuration', 0)
Description 乾杯の音頭をとるときに使うアニメーションです。 Attribute undefinedType ((baseEl: any, opts?: any) => Animation) | undefinedDefault undefined
Description トーストに表示されるヘッダー。 Attribute headerType string | undefinedDefault undefined
Description トーストに渡す追加の属性。 Attribute undefinedType undefined | { [key: string]: any; }Default undefined
Description 表示するアイコンの名前、または有効なSVGファイルへのパスを指定します。ion-icon`を参照。https://ionic.io/ionicons Attribute iconType string | undefinedDefault undefined
Description もし true ならば、トーストは表示されます。もし false ならば、トーストは閉じます。プレゼンテーションの細かい制御が必要な場合はこれを使用し、そうでない場合は toastController または trigger プロパティを使用してください。注意: トーストが終了しても isOpen は自動的に false に戻りません。あなたのコードでそれを行う必要があります。 Attribute is-openType booleanDefault false
Description trueの場合、オーバーレイが表示されたときにキーボードが自動的に解除されます。Attribute keyboard-closeType booleanDefault false
Description トーストのメッセージやボタンの配置を定義します。'baseline'を指定します。メッセージとボタンは同じ行に表示されます。メッセージテキストはメッセージコンテナ内で折り返すことができます。'stacked':ボタンコンテナとメッセージが重なるように表示されます。ボタンに長いテキストがある場合に使用します。 Attribute layoutType "baseline" | "stacked"Default 'baseline'
Description トーストの解散時に使用するアニメーションです。 Attribute undefinedType ((baseEl: any, opts?: any) => Animation) | undefinedDefault undefined
Description トーストに表示するメッセージ。このプロパティは、文字列としてカスタムHTMLを受け入れます。デフォルトではコンテンツはプレーンテキストとしてパースされます。カスタムHTMLを使用するには、Ionicの設定で innerHTMLTemplatesEnabled を true に設定する必要があります。 Attribute messageType IonicSafeString | string | undefinedDefault undefined
Description modeは、どのプラットフォームのスタイルを使用するかを決定します。 Attribute modeType "ios" | "md"Default undefined
Description 画面上のトーストの位置です。 Attribute positionType "bottom" | "middle" | "top"Default 'bottom'
Description trueの場合、トーストは半透明になります。modeが "ios" で、デバイスが backdrop-filter をサポートしている場合にのみ適用されます。Attribute translucentType booleanDefault false
Description クリックされたときにトーストを開かせるトリガー要素に対応するID。 Attribute triggerType string | undefinedDefault undefined
Name Description didDismissトーストが終了した後に発行されます。ionToastDidDismissの略記。 didPresentトーストがはじまった後に発行されます。ionToastWillDismissの略語。 ionToastDidDismissトーストが解散した後に発行されます。 ionToastDidPresentトーストが提示された後に発行されます。 ionToastWillDismiss乾杯が解散する前に発行されます。 ionToastWillPresentトーストが提示される前に発行されます。 willDismissトーストが終了する前に発行されます。ionToastWillDismissの略語です。 willPresentトーストが表示される前に発行されます。ionToastWillPresentの略記。
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>
Name Description buttonトーストの内側に表示される任意のボタン要素。 containerすべての子要素を包む要素。 header乾杯のヘッダーテキストです。 iconトーストの内容の横に表示されるアイコンです。 message乾杯の音頭の本文です。
Name Description --background乾杯の背景 --border-colorトーストのボーダーカラー --border-radiusトーストのボーダー半径 --border-styleトーストのボーダースタイル --border-widthトーストのボーダー幅 --box-shadow乾杯の箱影 --button-colorボタンテキストの色 --colorトーストの文字色 --end方向が左から右の場合は右から、方向が右から左の場合は左から位置すること --heightトーストの高さ --max-heightトーストの最大の高さ --max-widthトーストの最大幅 --min-heightトーストの最小の高さ --min-widthトーストの最小幅 --start方向が左から右の場合は左から、方向が右から左の場合は右から位置すること --white-space乾杯メッセージのホワイトスペース --widthトーストの幅
No slots available for this component.