diff --git a/docs/assets/scss/_component-examples.scss b/docs/assets/scss/_component-examples.scss index dd3cc190c2..91fcc4424b 100644 --- a/docs/assets/scss/_component-examples.scss +++ b/docs/assets/scss/_component-examples.scss @@ -332,6 +332,12 @@ overflow: auto; } +.scrollspy-example-2 { + position: relative; + height: 350px; + overflow: auto; +} + // Helpers .bd-example > { .bg-primary, diff --git a/docs/components/list-group.md b/docs/components/list-group.md index f3b5b7c892..5dbb6db408 100644 --- a/docs/components/list-group.md +++ b/docs/components/list-group.md @@ -167,3 +167,195 @@ Add nearly any HTML within, even for linked list groups like the one below, with {% 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. + +
+
+
+ +
+
+ +
+
+
+ +{% highlight html %} +
+
+ +
+
+ +
+
+{% 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`. + +
+{% highlight html %} + +
+ Home + Profile + Messages + Settings +
+ + +
+
...
+
...
+
...
+
...
+
+{% endhighlight %} +
+ +### 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 %} +
+
...
+
...
+
...
+
...
+
+{% 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 %} +
+ Home + Profile + Messages + Settings +
+ +
+
...
+
...
+
...
+
...
+
+ + +{% 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. + + + + + + + + + + + + + + + + + + + + + + + + + + +
Event TypeDescription
show.bs.tabThis event fires on tab show, but before the new tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively.
shown.bs.tabThis event fires on tab show after a tab has been shown. Use event.target and event.relatedTarget to target the active tab and the previous active tab (if available) respectively.
hide.bs.tabThis event fires when a new tab is to be shown (and thus the previous active tab is to be hidden). Use event.target and event.relatedTarget to target the current active tab and the new soon-to-be-active tab, respectively.
hidden.bs.tabThis event fires after a new tab is shown (and thus the previous active tab is hidden). Use event.target and event.relatedTarget to target the previous active tab and the new active tab, respectively.
+ +{% highlight js %} +$('a[data-toggle="list"]').on('shown.bs.tab', function (e) { + e.target // newly activated tab + e.relatedTarget // previous active tab +}) +{% endhighlight %} diff --git a/docs/components/navs.md b/docs/components/navs.md index e47a5a9e6c..05a2bfa415 100644 --- a/docs/components/navs.md +++ b/docs/components/navs.md @@ -199,20 +199,12 @@ When using a `