Skip to content

Commit cfabeb7

Browse files
julien-deramondmdo
andauthored
Fix StackBlitz Popovers and Tooltips examples (#36449)
* Fix StackBlitz Popovers and Tooltips examples * Rename shortcode example parameters * Reorder example shortcode doc params + fix Cspell * Remove 'stackblitz' param + use data-bs-title instead of title * Update site/layouts/partials/callout-warning-data-bs-title-vs-title.md Co-authored-by: Mark Otto <[email protected]> Co-authored-by: Mark Otto <[email protected]>
1 parent 22503d6 commit cfabeb7

File tree

10 files changed

+46
-35
lines changed

10 files changed

+46
-35
lines changed

.cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"semibold",
9494
"socio",
9595
"srcset",
96+
"stackblitz",
9697
"stickied",
9798
"Stylelint",
9899
"subnav",

site/content/docs/5.2/components/alerts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Alerts are available for any length of text, as well as an optional close button
2727

2828
Click the button below to show an alert (hidden with inline styles to start), then dismiss (and destroy) it with the built-in close button.
2929

30-
{{< example js_snippet="true" >}}
30+
{{< example stackblitz_add_js="true" >}}
3131
<div id="liveAlertPlaceholder"></div>
3232
<button type="button" class="btn btn-primary" id="liveAlertBtn">Show live alert</button>
3333
{{< /example >}}

site/content/docs/5.2/components/modal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ Have a bunch of buttons that all trigger the same modal with slightly different
444444

445445
Below is a live demo followed by example HTML and JavaScript. For more information, [read the modal events docs](#events) for details on `relatedTarget`.
446446

447-
{{< example js_snippet="true" >}}
447+
{{< example stackblitz_add_js="true" >}}
448448
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@mdo">Open modal for @mdo</button>
449449
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@fat">Open modal for @fat</button>
450450
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" data-bs-whatever="@getbootstrap">Open modal for @getbootstrap</button>

site/content/docs/5.2/components/popovers.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,21 @@ const popoverList = [...popoverTriggerList].map(popoverTriggerEl => new bootstra
4444

4545
### Live demo
4646

47-
We use JavaScript similar to the snippet above to render the following live popover. Titles are set via `title` attribute and body content is set via `data-bs-content`.
47+
We use JavaScript similar to the snippet above to render the following live popover. Titles are set via `data-bs-title` and body content is set via `data-bs-content`.
4848

49-
{{< example js_snippet="true" >}}
49+
{{< callout warning >}}
50+
{{< partial "callout-warning-data-bs-title-vs-title.md" >}}
51+
{{< /callout >}}
52+
53+
{{< example stackblitz_add_js="true" >}}
5054
<button type="button" class="btn btn-lg btn-danger" data-bs-toggle="popover" title="Popover title" data-bs-content="And here's some amazing content. It's very engaging. Right?">Click to toggle popover</button>
5155
{{< /example >}}
5256

5357
### Four directions
5458

5559
Four options are available: top, right, bottom, and left. Directions are mirrored when using Bootstrap in RTL. Set `data-bs-placement` to change the direction.
5660

57-
{{< example js_snippet="true" >}}
61+
{{< example stackblitz_add_js="true" >}}
5862
<button type="button" class="btn btn-secondary" data-bs-container="body" data-bs-toggle="popover" data-bs-placement="top" data-bs-content="Top popover">
5963
Popover on top
6064
</button>
@@ -87,11 +91,11 @@ You can customize the appearance of popovers using [CSS variables](#variables).
8791

8892
{{< scss-docs name="custom-popovers" file="site/assets/scss/_component-examples.scss" >}}
8993

90-
{{< example class="custom-popover-demo" js_snippet="true" >}}
94+
{{< example class="custom-popover-demo" stackblitz_add_js="true" >}}
9195
<button type="button" class="btn btn-secondary"
9296
data-bs-toggle="popover" data-bs-placement="right"
9397
data-bs-custom-class="custom-popover"
94-
title="Custom popover"
98+
data-bs-title="Custom popover"
9599
data-bs-content="This popover is themed via CSS variables.">
96100
Custom popover
97101
</button>
@@ -107,8 +111,8 @@ Use the `focus` trigger to dismiss popovers on the user's next click of a differ
107111
For proper cross-browser and cross-platform behavior, you must use the `<a>` tag, _not_ the `<button>` tag, and you also must include a [`tabindex`](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex) attribute.
108112
{{< /callout >}}
109113

110-
{{< example js_snippet="true" >}}
111-
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-bs-toggle="popover" data-bs-trigger="focus" title="Dismissible popover" data-bs-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
114+
{{< example stackblitz_add_js="true" >}}
115+
<a tabindex="0" class="btn btn-lg btn-danger" role="button" data-bs-toggle="popover" data-bs-trigger="focus" data-bs-title="Dismissible popover" data-bs-content="And here's some amazing content. It's very engaging. Right?">Dismissible popover</a>
112116
{{< /example >}}
113117

114118
```js
@@ -123,7 +127,7 @@ Elements with the `disabled` attribute aren't interactive, meaning users cannot
123127

124128
For disabled popover triggers, you may also prefer `data-bs-trigger="hover focus"` so that the popover appears as immediate visual feedback to your users as they may not expect to _click_ on a disabled element.
125129

126-
{{< example js_snippet="true" >}}
130+
{{< example stackblitz_add_js="true" >}}
127131
<span class="d-inline-block" tabindex="0" data-bs-toggle="popover" data-bs-trigger="hover focus" data-bs-content="Disabled popover">
128132
<button class="btn btn-primary" type="button" disabled>Disabled button</button>
129133
</span>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Building on the above example, you can create different toast color schemes with
197197

198198
Place toasts with custom CSS as you need them. The top right is often used for notifications, as is the top middle. If you're only ever going to show one toast at a time, put the positioning styles right on the `.toast`.
199199

200-
{{< example js_snippet="true" >}}
200+
{{< example stackblitz_add_js="true" >}}
201201
<form>
202202
<div class="mb-3">
203203
<label for="selectToastPlacement">Toast placement</label>

site/content/docs/5.2/components/tooltips.md

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,15 @@ const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstra
4545

4646
Hover over the links below to see tooltips:
4747

48-
{{< example class="tooltip-demo" js_snippet="true" >}}
49-
<p class="muted">Placeholder text to demonstrate some <a href="#" data-bs-toggle="tooltip" title="Default tooltip">inline links</a> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <a href="#" data-bs-toggle="tooltip" title="Another tooltip">real text</a>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you've now seen how <a href="#" data-bs-toggle="tooltip" title="Another one here too">these tooltips on links</a> can work in practice, once you use them on <a href="#" data-bs-toggle="tooltip" title="The last tip!">your own</a> site or project.
48+
{{< example class="tooltip-demo" stackblitz_add_js="true" >}}
49+
<p class="muted">Placeholder text to demonstrate some <a href="#" data-bs-toggle="tooltip" data-bs-title="Default tooltip">inline links</a> with tooltips. This is now just filler, no killer. Content placed here just to mimic the presence of <a href="#" data-bs-toggle="tooltip" data-bs-title="Another tooltip">real text</a>. And all that just to give you an idea of how tooltips would look when used in real-world situations. So hopefully you've now seen how <a href="#" data-bs-toggle="tooltip" data-bs-title="Another one here too">these tooltips on links</a> can work in practice, once you use them on <a href="#" data-bs-toggle="tooltip" data-bs-title="The last tip!">your own</a> site or project.
5050
</p>
5151
{{< /example >}}
5252

53+
{{< callout warning >}}
54+
{{< partial "callout-warning-data-bs-title-vs-title.md" >}}
55+
{{< /callout >}}
56+
5357
### Custom tooltips
5458

5559
{{< added-in "5.2.0" >}}
@@ -59,11 +63,11 @@ You can customize the appearance of tooltips using [CSS variables](#variables).
5963
{{< scss-docs name="custom-tooltip" file="site/assets/scss/_component-examples.scss" >}}
6064

6165

62-
{{< example class="tooltip-demo" js_snippet="true" >}}
66+
{{< example class="tooltip-demo" stackblitz_add_js="true" >}}
6367
<button type="button" class="btn btn-secondary"
6468
data-bs-toggle="tooltip" data-bs-placement="top"
6569
data-bs-custom-class="custom-tooltip"
66-
title="This top tooltip is themed via CSS variables.">
70+
data-bs-title="This top tooltip is themed via CSS variables.">
6771
Custom tooltip
6872
</button>
6973
{{< /example >}}
@@ -74,41 +78,41 @@ Hover over the buttons below to see the four tooltips directions: top, right, bo
7478

7579
<div class="bd-example tooltip-demo">
7680
<div class="bd-example-tooltips">
77-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">Tooltip on top</button>
78-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" title="Tooltip on right">Tooltip on right</button>
79-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Tooltip on bottom">Tooltip on bottom</button>
80-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" title="Tooltip on left">Tooltip on left</button>
81-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">Tooltip with HTML</button>
81+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Tooltip on top">Tooltip on top</button>
82+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="Tooltip on right">Tooltip on right</button>
83+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Tooltip on bottom">Tooltip on bottom</button>
84+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="Tooltip on left">Tooltip on left</button>
85+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-html="true" data-bs-title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">Tooltip with HTML</button>
8286
</div>
8387
</div>
8488

8589
```html
86-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" title="Tooltip on top">
90+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Tooltip on top">
8791
Tooltip on top
8892
</button>
89-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" title="Tooltip on right">
93+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="Tooltip on right">
9094
Tooltip on right
9195
</button>
92-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Tooltip on bottom">
96+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Tooltip on bottom">
9397
Tooltip on bottom
9498
</button>
95-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" title="Tooltip on left">
99+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="Tooltip on left">
96100
Tooltip on left
97101
</button>
98102
```
99103

100104
And with custom HTML added:
101105

102106
```html
103-
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-html="true" title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
107+
<button type="button" class="btn btn-secondary" data-bs-toggle="tooltip" data-bs-html="true" data-bs-title="<em>Tooltip</em> <u>with</u> <b>HTML</b>">
104108
Tooltip with HTML
105109
</button>
106110
```
107111

108112
With an SVG:
109113

110114
<div class="bd-example tooltip-demo">
111-
<a href="#" class="d-inline-block" data-bs-toggle="tooltip" title="Default tooltip">
115+
<a href="#" class="d-inline-block" data-bs-toggle="tooltip" data-bs-title="Default tooltip">
112116
<svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 100 100">
113117
<rect width="100%" height="100%" fill="#563d7c"/>
114118
<circle cx="50" cy="50" r="30" fill="#007bff"/>
@@ -165,7 +169,7 @@ You should only add tooltips to HTML elements that are traditionally keyboard-fo
165169

166170
```html
167171
<!-- HTML to write -->
168-
<a href="#" data-bs-toggle="tooltip" title="Some tooltip text!">Hover over me</a>
172+
<a href="#" data-bs-toggle="tooltip" data-bs-title="Some tooltip text!">Hover over me</a>
169173

170174
<!-- Generated markup by the plugin -->
171175
<div class="tooltip bs-tooltip-top" role="tooltip">
@@ -182,7 +186,7 @@ Elements with the `disabled` attribute aren't interactive, meaning users cannot
182186

183187
<div class="tooltip-demo">
184188
{{< example >}}
185-
<span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" title="Disabled tooltip">
189+
<span class="d-inline-block" tabindex="0" data-bs-toggle="tooltip" data-bs-title="Disabled tooltip">
186190
<button class="btn btn-primary" type="button" disabled>Disabled button</button>
187191
</span>
188192
{{< /example >}}

site/content/docs/5.2/forms/checks-radios.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Our checks use custom Bootstrap icons to indicate checked or indeterminate state
3636

3737
Checkboxes can utilize the `:indeterminate` pseudo class when manually set via JavaScript (there is no available HTML attribute for specifying it).
3838

39-
{{< example class="bd-example-indeterminate" js_snippet="true" >}}
39+
{{< example class="bd-example-indeterminate" stackblitz_add_js="true" >}}
4040
<div class="form-check">
4141
<input class="form-check-input" type="checkbox" value="" id="flexCheckIndeterminate">
4242
<label class="form-check-label" for="flexCheckIndeterminate">
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Feel free to use either `title` or `data-bs-title` in your HTML. When `title` is used, Popper will replace it automatically with `data-bs-title` when the element is rendered.

site/layouts/partials/scripts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
// Get extra classes for this example except '.bd-example'
3131
const classes = Array.from(event.target.closest('.bd-code-snippet').querySelector('.bd-example').classList).filter(x => x !== 'bd-example').join(' ')
3232

33-
const jsSnippet = event.target.closest('.bd-code-snippet').querySelector('.btn-edit').getAttribute('data-js-snippet')
33+
const jsSnippet = event.target.closest('.bd-code-snippet').querySelector('.btn-edit').getAttribute('data-sb-js-snippet')
3434
StackBlitzSDK.openBootstrapSnippet(htmlSnippet, jsSnippet, classes)
3535
})
3636
})

site/layouts/shortcodes/example.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@
44
`args` are all optional and can be one of the following:
55
* id: the `div`'s id - default: ""
66
* class: any extra class(es) to be added to the `div` - default: ""
7-
* js_snippet: add extra JS snippet to StackBlitz - default: `false`
8-
* show_preview: if the preview should be output in the HTML - default: `true`
7+
* lang: language used to display the code - default: "html"
98
* show_markup: if the markup should be output in the HTML - default: `true`
9+
* show_preview: if the preview should be output in the HTML - default: `true`
10+
* stackblitz_add_js: if extra JS snippet shoud le added to StackBlitz - default: `false`
1011
*/ -}}
1112

1213
{{- $id := .Get "id" -}}
1314
{{- $class := .Get "class" -}}
1415
{{- $lang := .Get "lang" | default "html" -}}
15-
{{- $show_preview := .Get "show_preview" | default true -}}
16+
{{- $stackblitz_add_js := .Get "stackblitz_add_js" | default false -}}
1617
{{- $show_markup := .Get "show_markup" | default true -}}
17-
{{- $js_snippet := .Get "js_snippet" | default false -}}
18+
{{- $show_preview := .Get "show_preview" | default true -}}
1819
{{- $input := .Inner -}}
1920

2021
<div class="bd-example-snippet bd-code-snippet">
@@ -29,7 +30,7 @@
2930
<div class="d-flex align-items-center highlight-toolbar bg-light ps-3 pe-2 py-1">
3031
<small class="font-monospace text-muted text-uppercase">{{- $lang -}}</small>
3132
<div class="d-flex ms-auto">
32-
<button type="button" class="btn-edit text-nowrap"{{ with $js_snippet }} data-js-snippet="{{ $js_snippet }}"{{ end }} title="Try it on StackBlitz">
33+
<button type="button" class="btn-edit text-nowrap"{{ with $stackblitz_add_js }} data-sb-js-snippet="{{ $stackblitz_add_js }}"{{ end }} title="Try it on StackBlitz">
3334
<svg class="bi" role="img" aria-label="Try it"><use xlink:href="#lightning-charge-fill"/></svg>
3435
</button>
3536
<button type="button" class="btn-clipboard mt-0 me-0" title="Copy to clipboard">

0 commit comments

Comments
 (0)