]> git.ipfire.org Git - ipfire.org.git/blob - static/scss/bootstrap-4.0.0-alpha.6/docs/components/collapse.md
.gitignore: Add .vscode
[ipfire.org.git] / static / scss / bootstrap-4.0.0-alpha.6 / docs / components / collapse.md
1 ---
2 layout: docs
3 title: Collapse
4 description: Toggle the visibility of content across your project with a few classes and our JavaScript plugins.
5 group: components
6 ---
7
8 The Bootstrap collapse plugin allows you to toggle content on your pages with a few classes thanks to some helpful JavaScript.
9
10 ## Contents
11
12 * Will be replaced with the ToC, excluding the "Contents" header
13 {:toc}
14
15 ## Example
16
17 Click the buttons below to show and hide another element via class changes:
18
19 - `.collapse` hides content
20 - `.collapsing` is applied during transitions
21 - `.collapse.show` shows content
22
23 You can use a link with the `href` attribute, or a button with the `data-target` attribute. In both cases, the `data-toggle="collapse"` is required.
24
25 {% example html %}
26 <p>
27 <a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
28 Link with href
29 </a>
30 <button class="btn btn-primary" type="button" data-toggle="collapse" data-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
31 Button with data-target
32 </button>
33 </p>
34 <div class="collapse" id="collapseExample">
35 <div class="card card-block">
36 Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident.
37 </div>
38 </div>
39 {% endexample %}
40
41 ## Accordion example
42
43 Extend the default collapse behavior to create an accordion.
44
45 {% example html %}
46 <div id="accordion" role="tablist" aria-multiselectable="true">
47 <div class="card">
48 <div class="card-header" role="tab" id="headingOne">
49 <h5 class="mb-0">
50 <a data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
51 Collapsible Group Item #1
52 </a>
53 </h5>
54 </div>
55
56 <div id="collapseOne" class="collapse show" role="tabpanel" aria-labelledby="headingOne">
57 <div class="card-block">
58 Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
59 </div>
60 </div>
61 </div>
62 <div class="card">
63 <div class="card-header" role="tab" id="headingTwo">
64 <h5 class="mb-0">
65 <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
66 Collapsible Group Item #2
67 </a>
68 </h5>
69 </div>
70 <div id="collapseTwo" class="collapse" role="tabpanel" aria-labelledby="headingTwo">
71 <div class="card-block">
72 Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
73 </div>
74 </div>
75 </div>
76 <div class="card">
77 <div class="card-header" role="tab" id="headingThree">
78 <h5 class="mb-0">
79 <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
80 Collapsible Group Item #3
81 </a>
82 </h5>
83 </div>
84 <div id="collapseThree" class="collapse" role="tabpanel" aria-labelledby="headingThree">
85 <div class="card-block">
86 Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
87 </div>
88 </div>
89 </div>
90 </div>
91 {% endexample %}
92
93 ## Accessibility
94
95 Be sure to add `aria-expanded` to the control element. This attribute explicitly defines the current state of the collapsible element to screen readers and similar assistive technologies. If the collapsible element is closed by default, it should have a value of `aria-expanded="false"`. If you've set the collapsible element to be open by default using the `show` class, set `aria-expanded="true"` on the control instead. The plugin will automatically toggle this attribute based on whether or not the collapsible element has been opened or closed.
96
97 Additionally, if your control element is targeting a single collapsible element – i.e. the `data-target` attribute is pointing to an `id` selector – you may add an additional `aria-controls` attribute to the control element, containing the `id` of the collapsible element. Modern screen readers and similar assistive technologies make use of this attribute to provide users with additional shortcuts to navigate directly to the collapsible element itself.
98
99 ## Usage
100
101 The collapse plugin utilizes a few classes to handle the heavy lifting:
102
103 - `.collapse` hides the content
104 - `.collapse.show` shows the content
105 - `.collapsing` is added when the transition starts, and removed when it finishes
106
107 These classes can be found in `_transitions.scss`.
108
109 ### Via data attributes
110
111 Just add `data-toggle="collapse"` and a `data-target` to the element to automatically assign control of a collapsible element. The `data-target` attribute accepts a CSS selector to apply the collapse to. Be sure to add the class `collapse` to the collapsible element. If you'd like it to default open, add the additional class `show`.
112
113 To add accordion-like group management to a collapsible control, add the data attribute `data-parent="#selector"`. Refer to the demo to see this in action.
114
115 ### Via JavaScript
116
117 Enable manually with:
118
119 {% highlight js %}
120 $('.collapse').collapse()
121 {% endhighlight %}
122
123 ### Options
124
125 Options can be passed via data attributes or JavaScript. For data attributes, append the option name to `data-`, as in `data-parent=""`.
126
127 <table class="table table-bordered table-striped table-responsive">
128 <thead>
129 <tr>
130 <th style="width: 100px;">Name</th>
131 <th style="width: 50px;">Type</th>
132 <th style="width: 50px;">Default</th>
133 <th>Description</th>
134 </tr>
135 </thead>
136 <tbody>
137 <tr>
138 <td>parent</td>
139 <td>selector</td>
140 <td>false</td>
141 <td>If a selector is provided, then all collapsible elements under the specified parent will be closed when this collapsible item is shown. (similar to traditional accordion behavior - this is dependent on the <code>panel</code> class)</td>
142 </tr>
143 <tr>
144 <td>toggle</td>
145 <td>boolean</td>
146 <td>true</td>
147 <td>Toggles the collapsible element on invocation</td>
148 </tr>
149 </tbody>
150 </table>
151
152 ### Methods
153
154 #### `.collapse(options)`
155
156 Activates your content as a collapsible element. Accepts an optional options `object`.
157
158 {% highlight js %}
159 $('#myCollapsible').collapse({
160 toggle: false
161 })
162 {% endhighlight %}
163
164 #### `.collapse('toggle')`
165
166 Toggles a collapsible element to shown or hidden.
167
168 #### `.collapse('show')`
169
170 Shows a collapsible element.
171
172 #### `.collapse('hide')`
173
174 Hides a collapsible element.
175
176 ### Events
177
178 Bootstrap's collapse class exposes a few events for hooking into collapse functionality.
179
180 <table class="table table-bordered table-striped table-responsive">
181 <thead>
182 <tr>
183 <th style="width: 150px;">Event Type</th>
184 <th>Description</th>
185 </tr>
186 </thead>
187 <tbody>
188 <tr>
189 <td>show.bs.collapse</td>
190 <td>This event fires immediately when the <code>show</code> instance method is called.</td>
191 </tr>
192 <tr>
193 <td>shown.bs.collapse</td>
194 <td>This event is fired when a collapse element has been made visible to the user (will wait for CSS transitions to complete).</td>
195 </tr>
196 <tr>
197 <td>hide.bs.collapse</td>
198 <td>
199 This event is fired immediately when the <code>hide</code> method has been called.
200 </td>
201 </tr>
202 <tr>
203 <td>hidden.bs.collapse</td>
204 <td>This event is fired when a collapse element has been hidden from the user (will wait for CSS transitions to complete).</td>
205 </tr>
206 </tbody>
207 </table>
208
209 {% highlight js %}
210 $('#myCollapsible').on('hidden.bs.collapse', function () {
211 // do something…
212 })
213 {% endhighlight %}