Tost dɛn we dɛn kin mek
Push notis to yu visitɔ dɛn wit tost, wan layt ɛn izi fɔ kɔstɔmayz alɛt mɛsej.
Tost na layt notis dɛn we dɛn mek fɔ falamakata di push notis dɛn we mobayl ɛn dɛsktɔp ɔpreshɔn sistem dɛn dɔn mek pipul dɛn lɛk. Dɛn bil dɛn wit fleksbɔks, so dɛn izi fɔ alaynɛd ɛn pozishɔn.
Ɔvaviu fɔ di Baybul
Tin dɛn fɔ no we yu de yuz di tost plɔgin:
- If yu de bil wi JavaSkript frɔm sɔs, i nid fɔ
util.js
. - Tost na opt-in fɔ pefɔmɛns rizin, so yu fɔ initialize am yusɛf .
- Duya mɛmba se na yu gɛt di wok fɔ put di tost dɛn.
- Tost dɛn go ayd ɔtomɛtik wan if yu nɔ spɛsifa
autohide: false
.
Di animashɔn ifɛkt fɔ dis kɔmpɔnɛnt de dipen pan di prefers-reduced-motion
midia kwɛstyɔn. Si di ridyus muvmɛnt sɛkshɔn na wi aksesibiliti dɔkyumentri .
Ɛgzampul dɛn
Men
Fɔ ɛnkɔrej tost dɛn we pɔsin kin ɛkstɛnd ɛn we pɔsin kin ebul fɔ tɔk bɔt, wi kin advays fɔ yuz ɛd ɛn bɔdi. Tost headers use display: flex
, alaw izi alaynɛshɔn fɔ kɔntinyu tank to wi margin ɛn flexbox yutiliti dɛn.
Tost dɛn kin fleksibul lɛk aw yu nid ɛn dɛn gɛt smɔl mak we dɛn nid. If nɔto so, wi nid wan ɛlimɛnt fɔ gɛt yu “tost” kɔntinyu ɛn wi rili ɛnkɔrej fɔ dismis bɔtin.
Translucent we de shayn
Tost dɛn kin translucent smɔl, bak, so dɛn kin miks oba ɛnitin we dɛn go apia oba. Fɔ brawza dɛn we de sɔpɔt di backdrop-filter
CSS prɔpati, wi go tray bak fɔ blɔk di ɛlimɛnt dɛn ɔnda wan tost.
Stak we dɛn de stak
We yu gɛt bɔku tost dɛn, wi kin difɔlt fɔ stak dɛn vertikal wan di we we pɔsin kin rid.
Di ples we dɛn fɔ put am
Put tost wit kɔstɔm CSS as yu nid dɛn. Bɔku tɛm, dɛn kin yuz di ɔp rayt say fɔ notis, ɛn na di ɔp pat na di midul. If yu go jɔs ɛva sho wan tost wan tɛm, put di pozishɔn stayl dɛn rayt na di .toast
.
Fɔ sistem dɛn we de jenarayz mɔ notis, tink bɔt fɔ yuz wan wrap ɛlimɛnt so dat dɛn go ebul fɔ stak izi wan.
Yu kin gɛt fansi bak wit fleksbɔks yutiliti fɔ alaynɛd tost dɛn ɔrizɔntal ɛn/ɔ vertikal wan.
Di we aw pɔsin kin ebul fɔ go de
Toasts are intended to be small interruptions to your visitors or users, so to help those with screen readers and similar assistive technologies, you should wrap your toasts in an aria-live
region. Changes to live regions (such as injecting/updating a toast component) are automatically announced by screen readers without needing to move the user’s focus or otherwise interrupt the user. Additionally, include aria-atomic="true"
to ensure that the entire toast is always announced as a single (atomic) unit, rather than announcing what was changed (which could lead to problems if you only update part of the toast’s content, or if displaying the same toast content at a later point in time). If the information needed is important for the process, e.g. for a list of errors in a form, then use the alert component instead of toast.
Note that the live region needs to be present in the markup before the toast is generated or updated. If you dynamically generate both at the same time and inject them into the page, they will generally not be announced by assistive technologies.
You also need to adapt the role
and aria-live
level depending on the content. If it’s an important message like an error, use role="alert" aria-live="assertive"
, otherwise use role="status" aria-live="polite"
attributes.
As the content you’re displaying changes, be sure to update the delay
timeout to ensure people have enough time to read the toast.
When using autohide: false
, you must add a close button to allow users to dismiss the toast.
JavaScript behavior
Usage
Initialize toasts via JavaScript:
Options
Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-
, as in data-animation=""
.
Name | Type | Default | Description |
---|---|---|---|
animation | boolean | true | Apply a CSS fade transition to the toast |
autohide | boolean | true | Auto hide the toast |
delay | number | 500 |
Delay hiding the toast (ms) |
Methods
Asynchronous methods and transitions
All API methods are asynchronous and start a transition. They return to the caller as soon as the transition is started but before it ends. In addition, a method call on a transitioning component will be ignored.
$().toast(options)
Attaches a toast handler to an element collection.
.toast('show')
Reveals an element’s toast. Returns to the caller before the toast has actually been shown (i.e. before the shown.bs.toast
event occurs). You have to manually call this method, instead your toast won’t show.
.toast('hide')
Hides an element’s toast. Returns to the caller before the toast has actually been hidden (i.e. before the hidden.bs.toast
event occurs). You have to manually call this method if you made autohide
to false
.
.toast('dispose')
Hides an element’s toast. Your toast will remain on the DOM but won’t show anymore.
Events
Event Type | Description |
---|---|
show.bs.toast | This event fires immediately when the show instance method is called. |
shown.bs.toast | This event is fired when the toast has been made visible to the user. |
hide.bs.toast | Dis ivent de faya wantɛm wantɛm we hide dɛn dɔn kɔl di instans mɛtɔd. |
ayd.bs.tost we dɛn dɔn ayd | Dis ivent de faya we di tost dɔn dɔn fɔ ayd frɔm di pɔsin we de yuz am. |