Editing
Collapsible Lists With Bootstrap
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== HTML == <syntaxhighlight lang="twig" enclose="div" highlight="3,4,7"> <div class="panel-group"> <div class="panel panel-default"> <div class="panel-heading" role="tab" id="collapse-list-heading-{{group.id}}"> <h2 class="panel-title">{{ group.name }} <button class="btn btn-default btn-xs btn-toggle-tutorial-list" type="button" data-toggle="collapse" data-target="#collapse-list-{{group.id}}" aria-expanded="false" aria-controls="collapse-list-{{group.id}}" title="toggle tutorial group"><span class="glyphicon glyphicon-chevron-down"></span></button></h2> </div> <div class="panel-body">{{ tutorials.count }} tutorial{% if tutorials.count != 1 %}s{% endif %}</div> <div class="panel-collapse collapse" id="collapse-list-{{ group_id }}" role="tabpanel" aria-labelledby="collapse-list-heading-{{group_id}}" aria-expanded="false"> <ul class="list-group"> <li class="list-group-item container-fluid">...</li> <li class="list-group-item container-fluid">...</li> <li class="list-group-item container-fluid">...</li> </ul> </div><!--end .panel-collapse--> </div><!--end .panel--> </div><!--end .panel--> </syntaxhighlight> Bootstrap provides all the JavaScript to expand and collapse the list once the required classes and attributes are set. Assigning the `aria-expanded="false"` attribute will cause the list to be collapsed initially. This doesn't necessarily have to be contained in a `.panel-group` container. * '''Header''' ** Target the heading element with `#collapse-list-heading-<nowiki>{{group.id}}</nowiki>`. * '''Button''' ** `.btn-toggle-tutorial-list` is the button's selector for the purposes of custom jQuery. This is to update the button's icon depending on the state of the list (collapsed or expanded); it doesn't have anything to do with the needs of Bootstrap. ** `type="button"` prevents the button from acting as a submit button. ** `data-target="#collapse-list-<nowiki>{{group.id}}</nowiki>"` Element to target. ** `aria-controls="collapse-list-<nowiki>{{group.id}}</nowiki>"` is for the purposes of acccessibility. ** `aria-expanded="false"` allows jQuery to test the collapsed state of the list. * '''Listings''' ** `class="panel-collapse collapse"` Bootstrap classes for the collapsing element. Again, `.panel-collapse` is in there just because this is a panel. ** `id="collapse-list-<nowiki>{{ group_id }}</nowiki>"`: target for the collapsible element; corresponds to the `data-target` attribute of the button control. ** `aria-labelledby="collapse-list-heading-<nowiki>{{group_id}}</nowiki>"`: Accessibility aid. ** `aria-expanded="false"`: Hook to test state of the collapsible element. ** Whatever is placed inside of the `.collapse` element will be hidden while the element is collapsed. In this case it's a `.list-group`.
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information