'
+ ].join('')
+ document.documentElement.style.overflowY = 'scroll'
+
+ const fixedEl = fixtureEl.querySelector('#fixed1')
+ const fixedEl2 = fixtureEl.querySelector('#fixed2')
+ const originalPadding = Number.parseInt(window.getComputedStyle(fixedEl).paddingRight, 10)
+ const originalPadding2 = Number.parseInt(window.getComputedStyle(fixedEl2).paddingRight, 10)
+ const expectedPadding = originalPadding + Scrollbar.getWidth()
+ const expectedPadding2 = originalPadding2 + Scrollbar.getWidth()
+
+ Scrollbar.hide()
+
+ let currentPadding = Number.parseInt(window.getComputedStyle(fixedEl).paddingRight, 10)
+ let currentPadding2 = Number.parseInt(window.getComputedStyle(fixedEl2).paddingRight, 10)
+ expect(fixedEl.getAttribute('data-bs-padding-right')).toEqual('0px', 'original fixed element padding should be stored in data-bs-padding-right')
+ expect(fixedEl2.getAttribute('data-bs-padding-right')).toEqual('5px', 'original fixed element padding should be stored in data-bs-padding-right')
+ expect(currentPadding).toEqual(expectedPadding, 'fixed element padding should be adjusted while opening')
+ expect(currentPadding2).toEqual(expectedPadding2, 'fixed element padding should be adjusted while opening')
+
+ Scrollbar.reset()
+ currentPadding = Number.parseInt(window.getComputedStyle(fixedEl).paddingRight, 10)
+ currentPadding2 = Number.parseInt(window.getComputedStyle(fixedEl2).paddingRight, 10)
+ expect(fixedEl.getAttribute('data-bs-padding-right')).toEqual(null, 'data-bs-padding-right should be cleared after closing')
+ expect(fixedEl2.getAttribute('data-bs-padding-right')).toEqual(null, 'data-bs-padding-right should be cleared after closing')
+ expect(currentPadding).toEqual(originalPadding, 'fixed element padding should be reset after closing')
+ expect(currentPadding2).toEqual(originalPadding2, 'fixed element padding should be reset after closing')
+ done()
+ })
+
+ it('should adjust the inline margin of sticky elements', done => {
+ fixtureEl.innerHTML = [
+ '
' +
+ '',
+ '
'
+ ].join('')
+ document.documentElement.style.overflowY = 'scroll'
+
+ const stickyTopEl = fixtureEl.querySelector('.sticky-top')
+ const originalMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)
+ const expectedMargin = originalMargin - Scrollbar.getWidth()
+ Scrollbar.hide()
+
+ let currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)
+ expect(stickyTopEl.getAttribute('data-bs-margin-right')).toEqual('0px', 'original sticky element margin should be stored in data-bs-margin-right')
+ expect(currentMargin).toEqual(expectedMargin, 'sticky element margin should be adjusted while opening')
+
+ Scrollbar.reset()
+ currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)
+
+ expect(stickyTopEl.getAttribute('data-bs-margin-right')).toEqual(null, 'data-bs-margin-right should be cleared after closing')
+ expect(currentMargin).toEqual(originalMargin, 'sticky element margin should be reset after closing')
+ done()
+ })
+
+ it('should not adjust the inline margin and padding of sticky and fixed elements when element do not have full width', () => {
+ fixtureEl.innerHTML = [
+ ''
+ ].join('')
+
+ const stickyTopEl = fixtureEl.querySelector('.sticky-top')
+ const originalMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)
+ const originalPadding = Number.parseInt(window.getComputedStyle(stickyTopEl).paddingRight, 10)
+
+ Scrollbar.hide()
+
+ const currentMargin = Number.parseInt(window.getComputedStyle(stickyTopEl).marginRight, 10)
+ const currentPadding = Number.parseInt(window.getComputedStyle(stickyTopEl).paddingRight, 10)
+
+ expect(currentMargin).toEqual(originalMargin, 'sticky element\'s margin should not be adjusted while opening')
+ expect(currentPadding).toEqual(originalPadding, 'sticky element\'s padding should not be adjusted while opening')
+
+ Scrollbar.reset()
+ })
+ })
+})
diff --git a/scss/_offcanvas.scss b/scss/_offcanvas.scss
new file mode 100644
index 000000000000..1eeb989666d1
--- /dev/null
+++ b/scss/_offcanvas.scss
@@ -0,0 +1,77 @@
+.offcanvas {
+ position: fixed;
+ bottom: 0;
+ z-index: $zindex-offcanvas;
+ display: flex;
+ flex-direction: column;
+ max-width: 100%;
+ color: $offcanvas-color;
+ visibility: hidden;
+ background-color: $offcanvas-bg-color;
+ background-clip: padding-box;
+ outline: 0;
+ @include box-shadow($offcanvas-box-shadow);
+ @include transition(transform $offcanvas-transition-duration ease-in-out);
+}
+
+.offcanvas-header {
+ display: flex;
+ justify-content: space-between;
+ padding: $offcanvas-padding-y $offcanvas-padding-x;
+
+ .btn-close {
+ padding: ($offcanvas-padding-y / 2) ($offcanvas-padding-x / 2);
+ margin: ($offcanvas-padding-y / -2) ($offcanvas-padding-x / -2) ($offcanvas-padding-y / -2) auto;
+ }
+}
+
+.offcanvas-title {
+ margin-bottom: 0;
+ line-height: $offcanvas-title-line-height;
+}
+
+.offcanvas-body {
+ flex-grow: 1;
+ padding: $offcanvas-padding-y $offcanvas-padding-x;
+ overflow-y: auto;
+}
+
+.offcanvas-start {
+ top: 0;
+ left: 0;
+ width: $offcanvas-horizontal-width;
+ border-right: $offcanvas-border-width solid $offcanvas-border-color;
+ transform: translateX(-100%);
+}
+
+.offcanvas-end {
+ top: 0;
+ right: 0;
+ width: $offcanvas-horizontal-width;
+ border-left: $offcanvas-border-width solid $offcanvas-border-color;
+ transform: translateX(100%);
+}
+
+.offcanvas-bottom {
+ right: 0;
+ left: 0;
+ height: $offcanvas-vertical-height;
+ max-height: 100%;
+ border-top: $offcanvas-border-width solid $offcanvas-border-color;
+ transform: translateY(100%);
+}
+
+.offcanvas.show {
+ transform: none;
+}
+
+.offcanvas-backdrop::before {
+ position: fixed;
+ top: 0;
+ left: 0;
+ z-index: $zindex-offcanvas - 1;
+ width: 100vw;
+ height: 100vh;
+ content: "";
+ background-color: $offcanvas-body-backdrop-color;
+}
diff --git a/scss/_variables.scss b/scss/_variables.scss
index 4ffcf18edc45..2668a790cb77 100644
--- a/scss/_variables.scss
+++ b/scss/_variables.scss
@@ -902,10 +902,11 @@ $form-validation-states: (
$zindex-dropdown: 1000 !default;
$zindex-sticky: 1020 !default;
$zindex-fixed: 1030 !default;
-$zindex-modal-backdrop: 1040 !default;
-$zindex-modal: 1050 !default;
-$zindex-popover: 1060 !default;
-$zindex-tooltip: 1070 !default;
+$zindex-offcanvas: 1040 !default;
+$zindex-modal-backdrop: 1050 !default;
+$zindex-modal: 1060 !default;
+$zindex-popover: 1070 !default;
+$zindex-tooltip: 1080 !default;
// scss-docs-end zindex-stack
@@ -1431,6 +1432,23 @@ $btn-close-white-filter: invert(1) grayscale(100%) brightness(200%) !default
// scss-docs-end close-variables
+// Offcanvas
+
+// scss-docs-start offcanvas-variables
+$offcanvas-padding-y: $modal-inner-padding !default;
+$offcanvas-padding-x: $modal-inner-padding !default;
+$offcanvas-horizontal-width: 400px !default;
+$offcanvas-vertical-height: 30vh !default;
+$offcanvas-transition-duration: .3s !default;
+$offcanvas-border-color: $modal-content-border-color !default;
+$offcanvas-border-width: $modal-content-border-width !default;
+$offcanvas-title-line-height: $modal-title-line-height !default;
+$offcanvas-bg-color: $modal-content-bg !default;
+$offcanvas-color: $modal-content-color !default;
+$offcanvas-body-backdrop-color: rgba($modal-backdrop-bg, $modal-backdrop-opacity) !default;
+$offcanvas-box-shadow: $modal-content-box-shadow-xs !default;
+// scss-docs-end offcanvas-variables
+
// Code
$code-font-size: $small-font-size !default;
diff --git a/scss/bootstrap.scss b/scss/bootstrap.scss
index f5f411753399..2687d099154a 100644
--- a/scss/bootstrap.scss
+++ b/scss/bootstrap.scss
@@ -42,6 +42,7 @@
@import "popover";
@import "carousel";
@import "spinners";
+@import "offcanvas";
// Helpers
@import "helpers";
diff --git a/site/assets/scss/_component-examples.scss b/site/assets/scss/_component-examples.scss
index b997689ed1af..91b5bbfd3e9a 100644
--- a/site/assets/scss/_component-examples.scss
+++ b/site/assets/scss/_component-examples.scss
@@ -201,6 +201,18 @@
}
}
+.bd-example-offcanvas {
+ @include border-start-radius(0);
+
+ .offcanvas {
+ position: static;
+ display: block;
+ height: 200px;
+ visibility: visible;
+ transform: translateX(0);
+ }
+}
+
// Tooltips
.tooltip-demo a {
white-space: nowrap;
diff --git a/site/content/docs/5.0/components/offcanvas.md b/site/content/docs/5.0/components/offcanvas.md
new file mode 100644
index 000000000000..9eacfd6b40fa
--- /dev/null
+++ b/site/content/docs/5.0/components/offcanvas.md
@@ -0,0 +1,256 @@
+---
+layout: docs
+title: Offcanvas
+description: Build hidden sidebars into your project for navigation, shopping carts, and more with a few classes and our JavaScript plugin.
+group: components
+toc: true
+---
+
+## How it works
+
+Offcanvas is a sidebar component that can be toggled via JavaScript to appear from the left, right, or bottom edge of the viewport. Buttons or anchors are used as triggers that are attached to specific elements you toggle, and `data` attributes are used to invoke our JavaScript.
+
+- Offcanvas shares some of the same JavaScript code as modals. Conceptually, they are quite similar, but they are separate plugins.
+- Similarly, some [source Sass](#sass) variables for offcanvas's styles and dimensions are inherited from the modal's variables.
+- When shown, offcanvas includes a default backdrop that can be clicked to hide the offcanvas.
+- Similar to modals, only one offcanvas can be shown at a time.
+
+**Heads up!** Given how CSS handles animations, you cannot use `margin` or `translate` on an `.offcanvas` element. Instead, use the class as an independent wrapping element.
+
+{{< callout info >}}
+{{< partial "callout-info-prefersreducedmotion.md" >}}
+{{< /callout >}}
+
+## Examples
+
+### Offcanvas components
+
+Below is a _static_ offcanvas example (meaning its `position`, `display`, and `visibility` have been overridden). Offcanvas includes support for a header with a close button and an optional body class for some initial `padding`. We suggest that you include offcanvas headers with dismiss actions whenever possible, or provide an explicit dismiss action.
+
+{{< example class="bd-example-offcanvas p-0 bg-light" >}}
+
+
+
Offcanvas
+
+
+
+ Content for the offcanvas goes here. You can place just about any Bootstrap component or custom elements here.
+
+
+{{< /example >}}
+
+### Live demo
+
+Use the buttons below to show and hide an offcanvas element via JavaScript that toggles the `.show` class on an element with the `.offcanvas` class.
+
+- `.offcanvas` hides content (default)
+- `.offcanvas.show` shows content
+
+You can use a link with the `href` attribute, or a button with the `data-bs-target` attribute. In both cases, the `data-bs-toggle="offcanvas"` is required.
+
+{{< example >}}
+
+ Link with href
+
+
+
+
+
+
Offcanvas
+
+
+
+
+ Some text as placeholder. In real life you can have the elements you have chosen. Like, text, images, lists, etc.
+
+{{< /example >}}
+
+## Placement
+
+There's no default placement for offcanvas components, so you must add one of the modifier classes below;
+
+- `.offcanvas-start` places offcanvas on the left of the viewport (shown above)
+- `.offcanvas-end` places offcanvas on the right of the viewport
+- `.offcanvas-bottom` places offcanvas on the bottom of the viewport
+
+Try the right and bottom examples out below.
+
+{{< example >}}
+
+
+
+
+
Offcanvas right
+
+
+
+ ...
+
+
+{{< /example >}}
+
+{{< example >}}
+
+
+
+
+
Offcanvas bottom
+
+
+
+ ...
+
+
+{{< /example >}}
+
+## Options
+
+By default, we disable scrolling on the `` when an offcanvas is visible and use a gray backdrop. Use the `data-bs-body` attribute to enable `` scrolling, or a combination of both options
+
+{{< example >}}
+
+
+
+
+
+
+
Colored with scrolling
+
+
+
+
Try scrolling the rest of the page to see this option in action.
+
+
+
+
+
Offcanvas with backdrop
+
+
+
+
.....
+
+
+
+
+
Backdroped with scrolling
+
+
+
+
Try scrolling the rest of the page to see this option in action.
+
+
+{{< /example >}}
+
+## Accessibility
+
+Since the offcanvas panel is conceptually a modal dialog, be sure to add `aria-labelledby="..."`—referencing the offcanvas title—to `.offcanvas`. Note that you don’t need to add `role="dialog"` since we already add it via JavaScript.
+
+## Sass
+
+### Variables
+
+{{< scss-docs name="offcanvas-variables" file="scss/_variables.scss" >}}
+
+## Usage
+
+The offcanvas plugin utilizes a few classes and attributes to handle the heavy lifting:
+
+- `.offcanvas` hides the content
+- `.offcanvas.show` shows the content
+- `.offcanvas-start` hides the offcanvas on the left
+- `.offcanvas-end` hides the offcanvas on the right
+- `.offcanvas-bottom` hides the offcanvas on the bottom
+- `data-bs-body="scroll"` enables `` scrolling when offcanvas is open
+- `data-bs-body="backdrop"` disables scrolling and creates a backdrop over the `` when offcanvas is open `(default)`
+- `data-bs-body="backdrop,scroll"` combines both options to enable `` scrolling and create a backdrop over the `` when offcanvas is open
+
+Add a dismiss button with the `data-bs-dismiss="offcanvas"` attribute, which triggers the JavaScript functionality. Be sure to use the `