Skip to content

Commit 4444f09

Browse files
committed
Add horizontal collapse support
1 parent 5968ef2 commit 4444f09

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

scss/_transitions.scss

+6
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,10 @@
1717
height: 0;
1818
overflow: hidden;
1919
@include transition($transition-collapse);
20+
21+
&.width {
22+
width: 0;
23+
height: auto;
24+
@include transition($transition-collapse-width);
25+
}
2026
}

scss/_variables.scss

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ $caret-spacing: $caret-width * .85 !default;
257257
$transition-base: all .2s ease-in-out !default;
258258
$transition-fade: opacity .15s linear !default;
259259
$transition-collapse: height .35s ease !default;
260+
$transition-collapse-width: width .35s ease !default;
260261

261262
$embed-responsive-aspect-ratios: () !default;
262263
$embed-responsive-aspect-ratios: join(

site/content/docs/4.6/components/collapse.md

+23
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,29 @@ Generally, we recommend using a button with the `data-target` attribute. While n
4040
</div>
4141
{{< /example >}}
4242

43+
## Horizontal
44+
45+
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. Feel free to write your own custom Sass, use inline styles, or use our [width utilities]({{< docsref "/utilities/sizing" >}}).
46+
47+
{{< callout info >}}
48+
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.**
49+
{{< /callout >}}
50+
51+
{{< example >}}
52+
<p>
53+
<button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseWidthExample" aria-expanded="false" aria-controls="collapseWidthExample">
54+
Toggle width collapse
55+
</button>
56+
</p>
57+
<div style="min-height: 120px;">
58+
<div class="collapse width" id="collapseWidthExample">
59+
<div class="card card-body" style="width: 320px;">
60+
This is some placeholder content for a horizontal collapse. It's hidden by default and shown when triggered.
61+
</div>
62+
</div>
63+
</div>
64+
{{< /example >}}
65+
4366
## Multiple targets
4467

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

0 commit comments

Comments
 (0)