Skip to content

Commit

Permalink
Add horizontal collapse support
Browse files Browse the repository at this point in the history
  • Loading branch information
mdo committed Jun 14, 2021
1 parent f30066c commit 369dfe9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
6 changes: 6 additions & 0 deletions scss/_transitions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
height: 0;
overflow: hidden;
@include transition($transition-collapse);

&.width {
width: 0;
height: auto;
@include transition($transition-collapse-width);
}
}
// scss-docs-end collapse-classes
1 change: 1 addition & 0 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,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
Expand Down
23 changes: 23 additions & 0 deletions site/content/docs/5.0/components/collapse.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,29 @@ Generally, we recommend using a button with the `data-bs-target` attribute. Whil
</div>
{{< /example >}}

## Horizontal

The collapse plugin also supports horizontal collapsing. Add the `.width` modifier class to transition the `width` instead of `height` and set a `width` on the immediate child element.

{{< 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 >}}
<p>
<button class="btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseWidthExample" aria-expanded="false" aria-controls="collapseWidthExample">
Toggle width collapse
</button>
</p>
<div style="min-height: 120px;">
<div class="collapse width" id="collapseWidthExample">
<div class="card card-body" style="width: 300px;">
This is some placeholder content for a horizontal collapse. It's hidden by default and shown when triggered.
</div>
</div>
</div>
{{< /example >}}

## Multiple targets

A `<button>` or `<a>` can show and hide multiple elements by referencing them with a selector in its `href` or `data-bs-target` attribute.
Expand Down

0 comments on commit 369dfe9

Please sign in to comment.