Skip to content

Commit d2477ab

Browse files
authored
Backport #32760 (#32827)
Add a live toast example to the docs
1 parent ee282af commit d2477ab

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

site/assets/js/application.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,17 @@
2424

2525
$('[data-toggle="popover"]').popover()
2626

27-
$('.toast')
27+
$('.bd-example .toast')
2828
.toast({
2929
autohide: false
3030
})
3131
.toast('show')
3232

33+
// Live toast demo
34+
$('#liveToastBtn').click(function () {
35+
$('#liveToast').toast('show')
36+
})
37+
3338
// Demos within modals
3439
$('.tooltip-test').tooltip()
3540
$('.popover-test').popover()

site/content/docs/4.5/components/toasts.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,50 @@ Toasts are as flexible as you need and have very little required markup. At a mi
4545
</div>
4646
{{< /example >}}
4747

48+
### Live
49+
50+
Click the button the below to show as toast (positioning with our utilities in the lower right corner) that has been hidden by default with `.hide`.
51+
52+
<div class="position-fixed bottom-0 right-0 p-3" style="z-index: 5; right: 0; bottom: 0;">
53+
<div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="2000">
54+
<div class="toast-header">
55+
{{< placeholder width="20" height="20" background="#007aff" class="rounded mr-2" text="false" title="false" >}}
56+
<strong class="mr-auto">Bootstrap</strong>
57+
<small>11 mins ago</small>
58+
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
59+
<span aria-hidden="true">&times;</span>
60+
</button>
61+
</div>
62+
<div class="toast-body">
63+
Hello, world! This is a toast message.
64+
</div>
65+
</div>
66+
</div>
67+
68+
<div class="bd-example">
69+
<button type="button" class="btn btn-primary" id="liveToastBtn">Show live toast</button>
70+
</div>
71+
72+
```html
73+
<button type="button" class="btn btn-primary" id="liveToastBtn">Show live toast</button>
74+
75+
<div class="position-fixed bottom-0 right-0 p-3" style="z-index: 5; right: 0; bottom: 0;">
76+
<div id="liveToast" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="2000">
77+
<div class="toast-header">
78+
<img src="..." class="rounded mr-2" alt="...">
79+
<strong class="mr-auto">Bootstrap</strong>
80+
<small>11 mins ago</small>
81+
<button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">
82+
<span aria-hidden="true">&times;</span>
83+
</button>
84+
</div>
85+
<div class="toast-body">
86+
Hello, world! This is a toast message.
87+
</div>
88+
</div>
89+
</div>
90+
```
91+
4892
### Translucent
4993

5094
Toasts are slightly translucent, too, so they blend over whatever they might appear over. For browsers that support the `backdrop-filter` CSS property, we'll also attempt to blur the elements under a toast.

0 commit comments

Comments
 (0)