Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tabs/Scrollspy/.nav/.list-group/.active independent of markup (<nav>, .nav-item, <li> etc...) #21807

Merged
merged 43 commits into from
Apr 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3bff97c
Fix active nav-link for nav markup
pvdlg Jan 21, 2017
9fe3960
Fix nav-justified for nav markup
pvdlg Jan 21, 2017
5b471f2
Fix nav-fill for nav markup
pvdlg Jan 21, 2017
df3dfc2
Add flex-fill utility that is referenced in the doc but not implemented
pvdlg Jan 21, 2017
536aefe
Add font-size utility used in the scroll spy docs
pvdlg Jan 21, 2017
1aee9d1
Detect parent to activate for both ul and nav markup, independently o…
pvdlg Jan 21, 2017
16e7a05
Remove unused variables
pvdlg Jan 21, 2017
98bbe1d
Unit test for both <ul> and <nav> markup
pvdlg Jan 21, 2017
009da31
Update nav docs to demonstrate nav-justified + <nav> markup
pvdlg Jan 21, 2017
2555b9e
Clarify dependency to nav, mentioned both <ul> and <nav> markup and a…
pvdlg Jan 21, 2017
29e71b7
Display dropdown as active when dropdown shown
pvdlg Jan 22, 2017
0c24034
Make tabs works with both <nav> and <ul> markup
pvdlg Jan 22, 2017
6fdfbd5
Find active tab / tab-pane independently of markup
pvdlg Jan 22, 2017
463caee
Fix tab-pane transitioning detection
pvdlg Jan 22, 2017
d69bb07
Remove unnecessary variables
pvdlg Jan 22, 2017
0515419
Add example with <nav> markup and JS
pvdlg Jan 22, 2017
47c439a
Fix html markup in docs
pvdlg Jan 22, 2017
753a6f5
Fix more markup
pvdlg Jan 22, 2017
3664142
Detect tabs list based on class .nav rather than elements
pvdlg Jan 22, 2017
7a7ae03
Merge branch 'twbs/v4-dev' into nav-scrollspy
pvdlg Jan 22, 2017
c5cebd2
Fix aria-control
pvdlg Jan 22, 2017
2392e9b
Rename NAV selector
pvdlg Jan 23, 2017
4afc8c0
Add tab pills and vertical tab pills examples
pvdlg Jan 23, 2017
15f7c44
Avoid double negative margin for <ul> markup
pvdlg Jan 23, 2017
ed386b8
Update unit test to reflect to replace tabs (that doesn't exist anymo…
pvdlg Jan 23, 2017
d7ebf9b
Fix htmlhint errors
pvdlg Jan 23, 2017
26e2361
Improve html examples
pvdlg Jan 23, 2017
689b922
Add scrollspy support to list-group
pvdlg Jan 24, 2017
3bdd1b0
Add tabs support to list-group
pvdlg Jan 24, 2017
d90ebde
Fix typo
pvdlg Jan 24, 2017
0384baa
Merge branch 'twbs/v4-dev' into nav-scrollspy
pvdlg Jan 24, 2017
b6c9ba6
Merge branch 'v4-dev' into nav-scrollspy
pvdlg Jan 25, 2017
9843459
Merge branch 'v4-dev' into nav-scrollspy
pvdlg Mar 19, 2017
569bd6c
Move nav-pills active classes under nav-pills
pvdlg Mar 19, 2017
2ac5591
Drop font-size utils
pvdlg Mar 20, 2017
f6bafb0
Remove flex-fill utils
pvdlg Mar 20, 2017
b5faf2b
Drop nav-link style for nav-justified and nav-fill
pvdlg Mar 20, 2017
f3e2886
Merge branch 'v4-dev' into nav-scrollspy
pvdlg Mar 28, 2017
e8b5f79
Merge branch 'v4-dev' into nav-scrollspy
pvdlg Mar 29, 2017
2ade5e7
Reverse 1a46d8c
pvdlg Mar 30, 2017
3227b7b
Update visual test for scroll spy and tab
pvdlg Mar 30, 2017
1996643
Fix copy/paste error in highlighted html (the actual code didn't change)
pvdlg Mar 30, 2017
eb7d9e0
Merge branch 'v4-dev' into nav-scrollspy
pvdlg Mar 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/assets/scss/_component-examples.scss
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,12 @@
overflow: auto;
}

.scrollspy-example-2 {
position: relative;
height: 350px;
overflow: auto;
}

// Helpers
.bd-example > {
.bg-primary,
Expand Down
192 changes: 192 additions & 0 deletions docs/components/list-group.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,195 @@ Add nearly any HTML within, even for linked list groups like the one below, with
</a>
</div>
{% endexample %}

## JavaScript behavior

Use the tab JavaScript plugin—include it individually or through the compiled `bootstrap.js` file—to extend our list group to create tabbable panes of local content.

<div class="bd-example" role="tabpanel">
<div class="row">
<div class="col-4">
<div class="list-group" id="list-tab" role="tablist">
<a class="list-group-item list-group-item-action active" id="list-home-list" data-toggle="tab" href="#list-home" role="tab" aria-controls="home">Home</a>
<a class="list-group-item list-group-item-action" id="list-profile-list" data-toggle="tab" href="#list-profile" role="tab" aria-controls="profile">Profile</a>
<a class="list-group-item list-group-item-action" id="list-messages-list" data-toggle="tab" href="#list-messages" role="tab" aria-controls="messages">Messages</a>
<a class="list-group-item list-group-item-action" id="list-settings-list" data-toggle="tab" href="#list-settings" role="tab" aria-controls="settings">Settings</a>
</div>
</div>
<div class="col-8">
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="list-home" role="tabpanel" aria-labelledby="list-home-list">
<p>Velit aute mollit ipsum ad dolor consectetur nulla officia culpa adipisicing exercitation fugiat tempor. Voluptate deserunt sit sunt nisi aliqua fugiat proident ea ut. Mollit voluptate reprehenderit occaecat nisi ad non minim tempor sunt voluptate consectetur exercitation id ut nulla. Ea et fugiat aliquip nostrud sunt incididunt consectetur culpa aliquip eiusmod dolor. Anim ad Lorem aliqua in cupidatat nisi enim eu nostrud do aliquip veniam minim.</p>
</div>
<div class="tab-pane fade" id="list-profile" role="tabpanel" aria-labelledby="list-profile-list">
<p>Cupidatat quis ad sint excepteur laborum in esse qui. Et excepteur consectetur ex nisi eu do cillum ad laborum. Mollit et eu officia dolore sunt Lorem culpa qui commodo velit ex amet id ex. Officia anim incididunt laboris deserunt anim aute dolor incididunt veniam aute dolore do exercitation. Dolor nisi culpa ex ad irure in elit eu dolore. Ad laboris ipsum reprehenderit irure non commodo enim culpa commodo veniam incididunt veniam ad.</p>
</div>
<div class="tab-pane fade" id="list-messages" role="tabpanel" aria-labelledby="list-messages-list">
<p>Ut ut do pariatur aliquip aliqua aliquip exercitation do nostrud commodo reprehenderit aute ipsum voluptate. Irure Lorem et laboris nostrud amet cupidatat cupidatat anim do ut velit mollit consequat enim tempor. Consectetur est minim nostrud nostrud consectetur irure labore voluptate irure. Ipsum id Lorem sit sint voluptate est pariatur eu ad cupidatat et deserunt culpa sit eiusmod deserunt. Consectetur et fugiat anim do eiusmod aliquip nulla laborum elit adipisicing pariatur cillum.</p>
</div>
<div class="tab-pane fade" id="list-settings" role="tabpanel" aria-labelledby="list-settings-list">
<p>Irure enim occaecat labore sit qui aliquip reprehenderit amet velit. Deserunt ullamco ex elit nostrud ut dolore nisi officia magna sit occaecat laboris sunt dolor. Nisi eu minim cillum occaecat aute est cupidatat aliqua labore aute occaecat ea aliquip sunt amet. Aute mollit dolor ut exercitation irure commodo non amet consectetur quis amet culpa. Quis ullamco nisi amet qui aute irure eu. Magna labore dolor quis ex labore id nostrud deserunt dolor eiusmod eu pariatur culpa mollit in irure.</p>
</div>
</div>
</div>
</div>
</div>

{% highlight html %}
<div class="row">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can remove this div (<div class="row">) from your example

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to make the sample code more concise ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes exactly

Copy link
Contributor Author

@pvdlg pvdlg Mar 29, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Then I'll remove <div class="col-4"> as well I suppose. I thought it would be helpful for the user to see how to make the vertical menu with the grid. But thinking about it now, it's true it makes the sample bigger and it's not really the place for that anyway. I'll change it tonight

<div class="col-4">
<div class="list-group" id="list-tab" role="tablist">
<a class="list-group-item list-group-item-action active" id="list-home-list" data-toggle="list" href="#list-home" role="tab" aria-controls="home">Home</a>
<a class="list-group-item list-group-item-action" id="list-profile-list" data-toggle="list" href="#list-profile" role="tab" aria-controls="profile">Profile</a>
<a class="list-group-item list-group-item-action" id="list-messages-list" data-toggle="list" href="#list-messages" role="tab" aria-controls="messages">Messages</a>
<a class="list-group-item list-group-item-action" id="list-settings-list" data-toggle="list" href="#list-settings" role="tab" aria-controls="settings">Settings</a>
</div>
</div>
<div class="col-8">
<div class="tab-content" id="nav-tabContent">
<div class="tab-pane fade show active" id="list-home" role="tabpanel" aria-labelledby="list-home-list">...</div>
<div class="tab-pane fade" id="list-profile" role="tabpanel" aria-labelledby="list-profile-list">...</div>
<div class="tab-pane fade" id="list-messages" role="tabpanel" aria-labelledby="list-messages-list">...</div>
<div class="tab-pane fade" id="list-settings" role="tabpanel" aria-labelledby="list-settings-list">...</div>
</div>
</div>
</div>
{% endhighlight %}

### Using data attributes

You can activate a list group navigation without writing any JavaScript by simply specifying `data-toggle="list"` or on an element. Use these data attributes on `.list-group-item`.

<div role="tabpanel">
{% highlight html %}
<!-- List group -->
<div class="list-group" id="myList" role="tablist">
<a class="list-group-item list-group-item-action active" data-toggle="list" href="#home" role="tab">Home</a>
<a class="list-group-item list-group-item-action" data-toggle="list" href="#profile" role="tab">Profile</a>
<a class="list-group-item list-group-item-action" data-toggle="list" href="#messages" role="tab">Messages</a>
<a class="list-group-item list-group-item-action" data-toggle="list" href="#settings" role="tab">Settings</a>
</div>

<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="home" role="tabpanel">...</div>
<div class="tab-pane" id="profile" role="tabpanel">...</div>
<div class="tab-pane" id="messages" role="tabpanel">...</div>
<div class="tab-pane" id="settings" role="tabpanel">...</div>
</div>
{% endhighlight %}
</div>

### Via JavaScript

Enable tabbable list item via JavaScript (each list item needs to be activated individually):

{% highlight js %}
$('#myList a').click(function (e) {
e.preventDefault()
$(this).tab('show')
})
{% endhighlight %}

You can activate individual list item in several ways:

{% highlight js %}
$('#myList a[href="#profile"]').tab('show') // Select tab by name
$('#myList a:first').tab('show') // Select first tab
$('#myList a:last').tab('show') // Select last tab
$('#myList li:eq(2) a').tab('show') // Select third tab (0-indexed)
{% endhighlight %}

### Fade effect

To make tabs panel fade in, add `.fade` to each `.tab-pane`. The first tab pane must also have `.show` to make the initial content visible.

{% highlight html %}
<div class="tab-content">
<div class="tab-pane fade show active" id="home" role="tabpanel">...</div>
<div class="tab-pane fade" id="profile" role="tabpanel">...</div>
<div class="tab-pane fade" id="messages" role="tabpanel">...</div>
<div class="tab-pane fade" id="settings" role="tabpanel">...</div>
</div>
{% endhighlight %}

### Methods

#### $().tab

Activates a list item element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.

{% highlight html %}
<div class="list-group" id="myList" role="tablist">
<a class="list-group-item list-group-item-action active" data-toggle="list" href="#home" role="tab">Home</a>
<a class="list-group-item list-group-item-action" data-toggle="list" href="#profile" role="tab">Profile</a>
<a class="list-group-item list-group-item-action" data-toggle="list" href="#messages" role="tab">Messages</a>
<a class="list-group-item list-group-item-action" data-toggle="list" href="#settings" role="tab">Settings</a>
</div>

<div class="tab-content">
<div class="tab-pane active" id="home" role="tabpanel">...</div>
<div class="tab-pane" id="profile" role="tabpanel">...</div>
<div class="tab-pane" id="messages" role="tabpanel">...</div>
<div class="tab-pane" id="settings" role="tabpanel">...</div>
</div>

<script>
$(function () {
$('#myList a:last').tab('show')
})
</script>
{% endhighlight %}

#### .tab('show')

Selects the given list item and shows its associated pane. Any other list item that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (i.e. before the `shown.bs.tab` event occurs).

{% highlight js %}
$('#someListItem').tab('show')
{% endhighlight %}

### Events

When showing a new tab, the events fire in the following order:

1. `hide.bs.tab` (on the current active tab)
2. `show.bs.tab` (on the to-be-shown tab)
3. `hidden.bs.tab` (on the previous active tab, the same one as for the `hide.bs.tab` event)
4. `shown.bs.tab` (on the newly-active just-shown tab, the same one as for the `show.bs.tab` event)

If no tab was already active, then the `hide.bs.tab` and `hidden.bs.tab` events will not be fired.

<table class="table table-bordered table-striped table-responsive">
<thead>
<tr>
<th style="width: 150px;">Event Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>show.bs.tab</td>
<td>This event fires on tab show, but before the new tab has been shown. Use <code>event.target</code> and <code>event.relatedTarget</code> to target the active tab and the previous active tab (if available) respectively.</td>
</tr>
<tr>
<td>shown.bs.tab</td>
<td>This event fires on tab show after a tab has been shown. Use <code>event.target</code> and <code>event.relatedTarget</code> to target the active tab and the previous active tab (if available) respectively.</td>
</tr>
<tr>
<td>hide.bs.tab</td>
<td>This event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use <code>event.target</code> and <code>event.relatedTarget</code> to target the current active tab and the new soon-to-be-active tab, respectively.</td>
</tr>
<tr>
<td>hidden.bs.tab</td>
<td>This event fires after a new tab is shown (and thus the previous active tab is hidden). Use <code>event.target</code> and <code>event.relatedTarget</code> to target the previous active tab and the new active tab, respectively.</td>
</tr>
</tbody>
</table>

{% highlight js %}
$('a[data-toggle="list"]').on('shown.bs.tab', function (e) {
e.target // newly activated tab
e.relatedTarget // previous active tab
})
{% endhighlight %}