Skip to content

Commit

Permalink
Add new offcanvas support to navbars
Browse files Browse the repository at this point in the history
Co-Authored-By: craftwerk <1193597+craftwerk@users.noreply.github.com>
  • Loading branch information
2 people authored and mdo committed Jul 16, 2021
1 parent 5c1691a commit 7c94f32
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 1 deletion.
31 changes: 30 additions & 1 deletion scss/_navbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,42 @@
.navbar-toggler {
display: none;
}

.offcanvas-header {
display: none;
}

.offcanvas {
position: inherit;
bottom: 0;
z-index: 1000;
flex-grow: 1;
visibility: visible !important; /* stylelint-disable-line declaration-no-important */
background-color: transparent;
border-right: 0;
border-left: 0;
@include transition(none);
transform: none;
}
.offcanvas-top,
.offcanvas-bottom {
height: auto;
border-top: 0;
border-bottom: 0;
}

.offcanvas-body {
display: flex;
flex-grow: 0;
padding: 0;
overflow-y: visible;
}
}
}
}
}
// scss-docs-end navbar-expand-loop


// Navbar themes
//
// Styles for switching between navbars with light or dark background.
Expand Down
64 changes: 64 additions & 0 deletions site/content/docs/5.0/components/navbar.md
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,70 @@ Sometimes you want to use the collapse plugin to trigger a container element for

When you do this, we recommend including additional JavaScript to move the focus programmatically to the container when it is opened. Otherwise, keyboard users and users of assistive technologies will likely have a hard time finding the newly revealed content - particularly if the container that was opened comes *before* the toggler in the document's structure. We also recommend making sure that the toggler has the `aria-controls` attribute, pointing to the `id` of the content container. In theory, this allows assistive technology users to jump directly from the toggler to the container it controls–but support for this is currently quite patchy.

### Offcanvas

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.

For example, to create an offcanvas navbar that expands into a normal navbar at the `xl` breakpoint, use `.navbar-expand-xl` and an offcanvas component around your navbar content.

{{< example >}}
<nav class="navbar navbar-light navbar-expand-xl bg-light fixed-top">
<div class="container-fluid">
<a class="navbar-brand" href="#">Offcanvas navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasNavbar" aria-controls="offcanvasNavbar">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasNavbar" aria-labelledby="offcanvasNavbarLabel">
<div class="offcanvas-header">
<h5 class="offcanvas-title" id="offcanvasNavbarLabel">Offcanvas</h5>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<ul class="navbar-nav justify-content-end flex-grow-1 pe-3">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Link</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="offcanvasNavbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</a>
<ul class="dropdown-menu" aria-labelledby="offcanvasNavbarDropdown">
<li><a class="dropdown-item" href="#">Action</a></li>
<li><a class="dropdown-item" href="#">Another action</a></li>
<li>
<hr class="dropdown-divider">
</li>
<li><a class="dropdown-item" href="#">Something else here</a></li>
</ul>
</li>
</ul>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</div>
</div>
</nav>
{{< /example >}}

For an offcanvas navbar that is always collapsed across all breakpoints, omit the `.navbar-expand-*` class entirely.

```html
<nav class="navbar navbar-light bg-light fixed-top">
<a class="navbar-brand" href="#">Offcanvas navbar</a>
<button class="navbar-toggler" type="button" data-bs-toggle="offcanvas" data-bs-target="#navbarOffcanvasAlways" aria-controls="navbarOffcanvasAlways">
<span class="navbar-toggler-icon"></span>
</button>
<div class="offcanvas offcanvas-end" tabindex="-1" id="navbarOffcanvasAlways" aria-labelledby="navbarOffcanvasAlwaysLabel">
...
</div>
</nav>
```

## Sass

### Variables
Expand Down

0 comments on commit 7c94f32

Please sign in to comment.