Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a "Close" tooltip to close buttons #1823

Merged
merged 35 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fae518d
Add tooltip on close btn for button close + modals + alerts + toasts …
hannahiss Feb 7, 2023
0ffd826
Remove duplicate disabled attribute to unblock Netlify
julien-deramond Feb 8, 2023
aa26488
move disabled attribute
hannahiss Feb 8, 2023
57c4210
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Feb 8, 2023
b86e9d1
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Mar 6, 2023
3b7271d
Changes after LM review:
hannahiss Mar 7, 2023
f2289a8
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Mar 7, 2023
40cdfc9
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Mar 13, 2023
0fe22c7
Stick to btn-close for 2nd button
hannahiss Mar 13, 2023
ba8b92b
Add tooltip to 2nd button since it's a "cross" close button
hannahiss Mar 13, 2023
e2331b0
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Mar 15, 2023
10faad0
Changes after LM review:
hannahiss Mar 15, 2023
51b2693
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Mar 23, 2023
45545d5
Add missing piece of js for btn-close tooltip on live alerts + have e…
hannahiss Mar 23, 2023
2e15627
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Mar 29, 2023
28945b1
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Apr 3, 2023
3ccef48
Merge branch 'main' into main-his-close-btn-tooltip
MewenLeHo Apr 24, 2023
c778d27
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss May 2, 2023
30d25c8
Merge branch 'main' into main-his-close-btn-tooltip
julien-deramond May 12, 2023
3d6bbcb
Julien's review:
hannahiss May 12, 2023
368aa00
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Jun 6, 2023
1443b2f
Merge branch 'main' into main-his-close-btn-tooltip
julien-deramond Jun 8, 2023
19802c8
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Jun 9, 2023
cf36e8e
- add close button in the list of js components
hannahiss Jun 9, 2023
334e7a9
enhance migration guide + snippets
hannahiss Jun 9, 2023
7511f31
Fix typo
julien-deramond Jun 12, 2023
021d1e1
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Jun 13, 2023
b4fba8b
Merge branch 'main' into main-his-close-btn-tooltip
hannahiss Jun 15, 2023
cd274e6
Add more info in migration guide and docs about close button tooltip …
hannahiss Jun 15, 2023
460279b
Consistency in introduction wording
julien-deramond Jun 19, 2023
43a914b
Move migration note from navs and tabs to navbar
julien-deramond Jun 19, 2023
ed287f0
.
julien-deramond Jun 19, 2023
13c64c9
put info about enabling tooltip on close button in a shortcode
hannahiss Jun 19, 2023
11e6b7d
Enhance enable-btn-close-tooltip
julien-deramond Jun 19, 2023
fd33bb5
move "enable tooltip" before "options"
hannahiss Jun 19, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion site/assets/js/snippets.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,21 @@

function alert(message, type, typeVisuallyHidden) {
julien-deramond marked this conversation as resolved.
Show resolved Hide resolved
const wrapper = document.createElement('div')
wrapper.innerHTML = `<div class="alert alert-${type} alert-dismissible" role="alert"><span class="alert-icon"><span class="visually-hidden">${typeVisuallyHidden}</span></span><p>${message}</p><button type="button" class="btn-close" data-bs-dismiss="alert"><span class="visually-hidden">Close</span></button></div>`
wrapper.innerHTML = `<div class="alert alert-${type} alert-dismissible" role="alert">
<span class="alert-icon"><span class="visually-hidden">${typeVisuallyHidden}</span></span><p>${message}</p>
<button type="button" class="btn-close" data-bs-dismiss="alert" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close">
<span class="visually-hidden">Close</span></button></div>`

alertPlaceholder.append(wrapper)

// Create btn-close's tooltip after innerHTML has been modified
julien-deramond marked this conversation as resolved.
Show resolved Hide resolved
const tooltip = new boosted.Tooltip(wrapper.querySelector('.btn-close'))
// Hide tooltip when clicking on live alert's btn-close
julien-deramond marked this conversation as resolved.
Show resolved Hide resolved
wrapper.querySelectorAll('.btn-close').forEach(closeBtn => {
closeBtn.addEventListener('click', () => {
tooltip.hide()
})
})
}

if (alertTrigger) {
Expand Down
6 changes: 3 additions & 3 deletions site/content/docs/5.3/components/alerts.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const alert = (message, type, typeVisuallyHidden) => {
' <p>',
` ${message}`,
' </p>',
' <button type="button" class="btn-close" data-bs-dismiss="alert">',
' <button type="button" class="btn-close" data-bs-dismiss="alert" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close">',
' <span class="visually-hidden">Close</span>',
' </button>',
'</div>'
louismaximepiton marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -148,7 +148,7 @@ You can see this in action with a live demo:
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<span class="alert-icon"><span class="visually-hidden">Warning</span></span>
<p>Warning notification text goes here.</p>
<button type="button" class="btn-close" data-bs-dismiss="alert"><span class="visually-hidden">Close</span></button>
<button type="button" class="btn-close" data-bs-dismiss="alert" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close"><span class="visually-hidden">Close</span></button>
julien-deramond marked this conversation as resolved.
Show resolved Hide resolved
</div>
{{< /example >}}

Expand Down Expand Up @@ -177,7 +177,7 @@ Add `.bg-dark` to the `.alert` for a dark variant. Close button can be inverted
<div class="alert alert-warning alert-dismissible fade show bg-dark" role="alert">
<span class="alert-icon"><span class="visually-hidden">Warning</span></span>
<p>Warning notification text goes here.</p>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="alert"><span class="visually-hidden">Close</span></button>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="alert" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close"><span class="visually-hidden">Close</span></button>
</div>
{{< /example >}}

Expand Down
12 changes: 6 additions & 6 deletions site/content/docs/5.3/components/close-button.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,37 @@ toc: true
Provide an option to dismiss or close a component with `.btn-close`. Default styling is limited, but highly customizable. Modify the Sass variables to replace the default `mask-image`. **Be sure to include text for screen readers**, as we've done with `<span class="visually-hidden">`.

{{< example >}}
<button type="button" class="btn-close"><span class="visually-hidden">Close</span></button>
<button type="button" class="btn-close" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close"><span class="visually-hidden">Close</span></button>
{{< /example >}}

## Disabled state

Disabled close buttons change their `color`. We've also applied `pointer-events: none` and `user-select: none` to preventing hover and active states from triggering.

{{< example >}}
<button type="button" class="btn-close" disabled><span class="visually-hidden">Close</span></button>
<button type="button" class="btn-close" disabled data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close"><span class="visually-hidden">Close</span></button>
{{< /example >}}

## Dark variant

Add `.btn-close-white` to the `.btn-close` for a dark variant.

{{< example class="bg-dark" >}}
<button type="button" class="btn-close btn-close-white"><span class="visually-hidden">Close</span></button>
<button type="button" class="btn-close btn-close-white" disabled><span class="visually-hidden">Close</span></button>
<button type="button" class="btn-close btn-close-white" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close"><span class="visually-hidden">Close</span></button>
<button type="button" class="btn-close btn-close-white" disabled data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close"><span class="visually-hidden">Close</span></button>
{{< /example >}}

## Without specific class

Close buttons can also be created without `.btn-close` to reduce the size of your CSS bundle.

{{< example >}}
<button type="button" class="btn btn-icon btn-no-outline">
<button type="button" class="btn btn-icon btn-no-outline" data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close">
<svg width="1.25rem" height="1.25rem" fill="currentColor" aria-hidden="true" focusable="false"><use xlink:href="/docs/{{< param docs_version >}}/assets/img/boosted-sprite.svg#delete"></use></svg>
<span class="visually-hidden">Close</span>
</button>

<button type="button" class="btn btn-icon btn-no-outline" disabled>
<button type="button" class="btn btn-icon btn-no-outline" disabled data-bs-toggle="tooltip" data-bs-placement="bottom" data-bs-title="Close">
<svg width="1.25rem" height="1.25rem" fill="currentColor" aria-hidden="true" focusable="false"><use xlink:href="/docs/{{< param docs_version >}}/assets/img/boosted-sprite.svg#delete"></use></svg>
<span class="visually-hidden">Close</span>
</button>
Expand Down
Loading