Skip to content

Commit 24d79fe

Browse files
authored
Add example of dark navbar and offcanvas to docs (#36510)
1 parent ac0b87b commit 24d79fe

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

site/assets/js/snippets.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,12 @@
141141
// Offcanvas
142142
// -------------------------------
143143
// 'Offcanvas components' example in docs only
144-
const myOffcanvas = document.querySelector('.bd-example-offcanvas #offcanvas')
144+
const myOffcanvas = document.querySelectorAll('.bd-example-offcanvas .offcanvas')
145145
if (myOffcanvas) {
146-
myOffcanvas.addEventListener('show.bs.offcanvas', event => {
147-
event.preventDefault()
148-
}, false)
146+
myOffcanvas.forEach(offcanvas => {
147+
offcanvas.addEventListener('show.bs.offcanvas', event => {
148+
event.preventDefault()
149+
}, false)
150+
})
149151
}
150152
})()

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ When you do this, we recommend including additional JavaScript to move the focus
670670

671671
### Offcanvas
672672

673-
Transform your expanding and collapsing navbar into an offcanvas drawer with the offcanvas plugin. We extend both the offcanvas default styles and use our `.navbar-expand-*` classes to create a dynamic and flexible navigation sidebar.
673+
Transform your expanding and collapsing navbar into an offcanvas drawer with the [offcanvas component]({{< docsref "/components/offcanvas" >}}). We extend both the offcanvas default styles and use our `.navbar-expand-*` classes to create a dynamic and flexible navigation sidebar.
674674

675675
In the example below, to create an offcanvas navbar that is always collapsed across all breakpoints, omit the `.navbar-expand-*` class entirely.
676676

@@ -732,6 +732,52 @@ To create an offcanvas navbar that expands into a normal navbar at a specific br
732732
</nav>
733733
```
734734

735+
When using offcanvas in a dark navbar, be aware that you may need to have a dark background on the offcanvas content to avoid the text becoming illegible. In the example below, we add `.navbar-dark` and `.bg-dark` to the `.navbar`, `.text-bg-dark` to the `.offcanvas`, `.dropdown-menu-dark` to `.dropdown-menu`, and `.btn-close-white` to `.btn-close` for proper styling with a dark offcanvas.
736+
737+
{{< example >}}
738+
<nav class="navbar navbar-dark bg-dark fixed-top">
739+
<div class="container-fluid">
740+
<a class="navbar-brand" href="#">Offcanvas dark navbar</a>
741+
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasDarkNavbar" aria-controls="offcanvasDarkNavbar">
742+
<span class="navbar-toggler-icon"></span>
743+
</button>
744+
<div class="offcanvas offcanvas-end text-bg-dark" tabindex="-1" id="offcanvasDarkNavbar" aria-labelledby="offcanvasDarkNavbarLabel">
745+
<div class="offcanvas-header">
746+
<h5 class="offcanvas-title" id="offcanvasDarkNavbarLabel">Dark offcanvas</h5>
747+
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvas" aria-label="Close"></button>
748+
</div>
749+
<div class="offcanvas-body">
750+
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
751+
<li class="nav-item">
752+
<a class="nav-link active" aria-current="page" href="#">Home</a>
753+
</li>
754+
<li class="nav-item">
755+
<a class="nav-link" href="#">Link</a>
756+
</li>
757+
<li class="nav-item dropdown">
758+
<a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
759+
Dropdown
760+
</a>
761+
<ul class="dropdown-menu dropdown-menu-dark">
762+
<li><a class="dropdown-item" href="#">Action</a></li>
763+
<li><a class="dropdown-item" href="#">Another action</a></li>
764+
<li>
765+
<hr class="dropdown-divider">
766+
</li>
767+
<li><a class="dropdown-item" href="#">Something else here</a></li>
768+
</ul>
769+
</li>
770+
</ul>
771+
<form class="d-flex" role="search">
772+
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
773+
<button class="btn btn-success" type="submit">Search</button>
774+
</form>
775+
</div>
776+
</div>
777+
</div>
778+
</nav>
779+
{{< /example >}}
780+
735781
## CSS
736782

737783
### Variables

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ You can use a link with the `href` attribute, or a button with the `data-bs-targ
7979
</div>
8080
{{< /example >}}
8181

82+
### Dark offcanvas
83+
84+
Change the appearance of offcanvases with utilities to better match them to different contexts like dark navbars. Here we add `.text-bg-dark` to the `.offcanvas` and `.btn-close-white` to `.btn-close` for proper styling with a dark offcanvas. If you have dropdowns within, consider also adding `.dropdown-menu-dark` to `.dropdown-menu`.
85+
86+
{{< example class="bd-example-offcanvas p-0 bg-light overflow-hidden" >}}
87+
<div class="offcanvas offcanvas-start show text-bg-dark" tabindex="-1" id="offcanvasDark" aria-labelledby="offcanvasDarkLabel">
88+
<div class="offcanvas-header">
89+
<h5 class="offcanvas-title" id="offcanvasDarkLabel">Offcanvas</h5>
90+
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="offcanvasDark" aria-label="Close"></button>
91+
</div>
92+
<div class="offcanvas-body">
93+
<p>Place offcanvas content here.</p>
94+
</div>
95+
</div>
96+
{{< /example >}}
97+
8298
### Body scrolling
8399

84100
Scrolling the `<body>` element is disabled when an offcanvas and its backdrop are visible. Use the `data-bs-scroll` attribute to enable `<body>` scrolling.

0 commit comments

Comments
 (0)