From 359ed099e5b2f82bd602f2a6c45f43af8f2c87e8 Mon Sep 17 00:00:00 2001 From: Mark Otto Date: Mon, 14 Jun 2021 23:25:11 +0300 Subject: [PATCH] Add horizontal collapse support --- js/src/collapse.js | 3 ++- js/tests/unit/collapse.spec.js | 2 +- scss/_transitions.scss | 6 +++++ scss/_variables.scss | 1 + site/content/docs/5.0/components/collapse.md | 23 ++++++++++++++++++++ 5 files changed, 33 insertions(+), 2 deletions(-) diff --git a/js/src/collapse.js b/js/src/collapse.js index 8831510dfd..22bd31f9b3 100644 --- a/js/src/collapse.js +++ b/js/src/collapse.js @@ -50,6 +50,7 @@ const CLASS_NAME_SHOW = 'show' const CLASS_NAME_COLLAPSE = 'collapse' const CLASS_NAME_COLLAPSING = 'collapsing' const CLASS_NAME_COLLAPSED = 'collapsed' +const CLASS_NAME_HORIZONTAL = 'collapse-horizontal' const WIDTH = 'width' const HEIGHT = 'height' @@ -266,7 +267,7 @@ class Collapse extends BaseComponent { } _getDimension() { - return this._element.classList.contains(WIDTH) ? WIDTH : HEIGHT + return this._element.classList.contains(CLASS_NAME_HORIZONTAL) ? WIDTH : HEIGHT } _getParent() { diff --git a/js/tests/unit/collapse.spec.js b/js/tests/unit/collapse.spec.js index 11d8d52bf5..9bce3f0bb0 100644 --- a/js/tests/unit/collapse.spec.js +++ b/js/tests/unit/collapse.spec.js @@ -225,7 +225,7 @@ describe('Collapse', () => { }) it('should show a collapsed element on width', done => { - fixtureEl.innerHTML = '
' + fixtureEl.innerHTML = '
' const collapseEl = fixtureEl.querySelector('div') const collapse = new Collapse(collapseEl, { diff --git a/scss/_transitions.scss b/scss/_transitions.scss index 2905df45cd..bfb26aa8ac 100644 --- a/scss/_transitions.scss +++ b/scss/_transitions.scss @@ -17,5 +17,11 @@ height: 0; overflow: hidden; @include transition($transition-collapse); + + &.collapse-horizontal { + width: 0; + height: auto; + @include transition($transition-collapse-width); + } } // scss-docs-end collapse-classes diff --git a/scss/_variables.scss b/scss/_variables.scss index aa4d4ff2fb..7f93df4e34 100644 --- a/scss/_variables.scss +++ b/scss/_variables.scss @@ -398,6 +398,7 @@ $transition-base: all .2s ease-in-out !default; $transition-fade: opacity .15s linear !default; // scss-docs-start collapse-transition $transition-collapse: height .35s ease !default; +$transition-collapse-width: width .35s ease !default; // scss-docs-end collapse-transition // stylelint-disable function-disallowed-list diff --git a/site/content/docs/5.0/components/collapse.md b/site/content/docs/5.0/components/collapse.md index ac84ca9649..3704fb636b 100644 --- a/site/content/docs/5.0/components/collapse.md +++ b/site/content/docs/5.0/components/collapse.md @@ -40,6 +40,29 @@ Generally, we recommend using a button with the `data-bs-target` attribute. Whil {{< /example >}} +## Horizontal + +The collapse plugin also supports horizontal collapsing. Add the `.collapse-horizontal` modifier class to transition the `width` instead of `height` and set a `width` on the immediate child element. Feel free to write your own custom Sass, use inline styles, or use our [width utilities]({{< docsref "/utilities/sizing" >}}). + +{{< callout info >}} +Please note that while the example below has a `min-height` set to avoid excessive repaints in our docs, this is not explicitly required. **Only the `width` on the child element is required.** +{{< /callout >}} + +{{< example >}} +

+ +

+
+
+
+ This is some placeholder content for a horizontal collapse. It's hidden by default and shown when triggered. +
+
+
+{{< /example >}} + ## Multiple targets A `