Interface à onglets
Needs translation
Purpose
Dynamically stacks multiple sections of content, transforming them into a tabbed interface. Implements the WAI-ARIA tab panel design pattern for large screens and the WAI-ARIA accordion design pattern for small screens.
Working example
How to implement
Tabbed interface
- Add a
div
element to the page with the classwb-tabs
. - Add a
div
element to the previousdiv
element with the classtabpanels
. - For each tab panel, add a
details
element with a uniqueid
. Addopen="open"
for the tab panel that should be open by default.<div class="wb-tabs"> <div class="tabpanels"> <details id="details-panel1"> ... </details> <details id="details-panel2" open="open"> ... </details>
- Add a
summary
element with the label of the tab to eachdetails
element.<details id="details-panel1"> <summary>Example 1</summary> ... </details> <details id="details-panel2" open="open"> <summary>Example 2</summary> ... </details>
- Add the tab panel content after each
summary
element.
Code
<div class="wb-tabs">
<div class="tabpanels">
<details id="details-panel1">
<summary>Example 1</summary>
<p>
...
</p>
</details>
<details id="details-panel2" open="open">
<summary>Example 2</summary>
<p>
...
</p>
</details>
...
</div>
</div>
Carousel
- Add a
div
element to the page with the classwb-tabs
and either the styling classcarousel-s1
orcarousel-s2
. - Add a
div
element to the previousdiv
element with the classtabpanels
. - For each tab panel, add a
div
element with a unique id,role="tabpanel"
andclass="out"
. For the tab panel that should be opened by default, replace theout
class within
. - Specify the tab panel transition type by adding one of the following classes to the
div
element for each of the tab panels:fade
: Fading transitionslide
: Horizontal sliding transitionslidevert
: Vertical sliding transition
<div class="wb-tabs carousel-s1"> <div class="tabpanels"> <div role="tabpanel" id="panel1" class="in fade"> </div> <div role="tabpanel" id="panel2" class="out fade"> </div> </div> </div>
- Add a
figure
element to each tab panel. - Add content to each
figure
element:- Image: Add an image to the
figure
element followed by afigcaption
element with the caption for the tab panel.<div role="tabpanel" id="panel1" class="in fade"> <figure> <img src="img/protect-environment.jpg" alt="Panel 1" /> <figcaption> <p> Take Note: <a href="http://www.tc.gc.ca/eng/civilaviation/opssvs/general-personnel-changes-1814.htm">Renewal of the Aviation Document Booklet</a> <br /> Learn more about <a href="http://www.tc.gc.ca/eng/air-menu.htm">air transportation</a> in Canada. </p> </figcaption> </figure> </div>
- Video: Add a multimedia player to the
figure
element according to the multimedia player documentation.<div role="tabpanel" id="panel1" class="in fade"> <figure class="wb-mltmd"> <video poster="http://www.servicecanada.gc.ca/eng/video/images/te-lj-eng.jpg" title="Looking for a Job"> <source type="video/webm" src="http://video2.servicecanada.gc.ca/video/boew-wet/te-lj-eng.webm" /> <source type="video/mp4" src="http://video2.servicecanada.gc.ca/video/boew-wet/te-lj-eng.mp4" /> <track src="../multimedia/cpts-lg-en.html" kind="captions" data-type="text/html" srclang="en" label="English" /> </video> <figcaption> <p>Looking for a Job (<a href="http://www.servicecanada.gc.ca/eng/video/lj.shtml">Transcript</a>)</p> </figcaption> </figure> </div>
- Other content: Add content to the
figure
element followed by afigcaption
element with the caption for the tab panel.<div role="tabpanel" id="panel1" class="in fade"> <figure> <table> ... </table> <figcaption> <p>Tab panel caption</p> </figcaption> </figure> </div>
- Image: Add an image to the
- Add a
ul
element withrole="tablist"
at the start of thediv
element with thewb-tabs
class. - For each tab panel, add an
li
element to the previousul
element. Addclass="active"
for the tab panel that should be open by default. - Add an
a
element to eachli
element - Add to each
li
element ana
element with the label of the tab and that links to the associated tab panel.<ul role="tablist"> <li class="active"><a href="#panel27">Tab 1</a></li> <li><a href="#panel28">Tab 2</a></li> ... </ul>
- Optional: Override the default settings using the configuration options.
- Optional: Add an external link that affects which tab is visible. The href attribute includes the id of the panel to make visible. (v4.0.8+)
<p><a href="#panel3" class="wb-tabs-ext">Show the third panel</a></p>
Code
<div class="wb-tabs carousel-s1">
<ul role="tablist">
<li class="active"><a href="#panel1">Tab 1</a></li>
<li><a href="#panel2">Tab 2</a></li>
...
</ul>
<div class="tabpanels">
<div role="tabpanel" id="panel1" class="in fade">
<figure>
<img src="img/protect-environment.jpg" alt="Panel 1" />
<figcaption>
<p>
...
</p>
</figcaption>
</figure>
</div>
<div role="tabpanel" id="panel2" class="out fade">
<figure>
<img src="img/banff.jpg" alt="Panel 2" />
<figcaption>
<p>
...
</p>
</figcaption>
</figure>
</div>
...
</div>
</div>
Configuration options - Tabbed interface and carousel
Option | Description | How to configure | Values |
---|---|---|---|
Update the URL hash (data-wb-tabs ) (v4.0.9+) |
Configure the tab interface or carousel to update the URL hash every time the tab panel changes through the updateHash property of the data-wb-tabs attribute. |
Add the data-wb-tabs attribute to the element with class="wb-tabs" and include the updateHash property with a true or false value.
|
|
Update the URL hash (update-hash ) (v4.0.9+) |
Configure the tab interface or carousel to update the URL hash every time the tab panel changes through the update-hash class. |
Add update-hash after the wb-tabs class.
|
|
Ignore session storage (data-wb-tabs ) (v4.0.12+) |
Configure the tab interface to remain on the first or default selected tab on all page loads through the ignoreSession property of the data-wb-tabs attribute. |
Add the data-wb-tabs attribute to the element with class="wb-tabs" and include the ignoreSession property with a true or false value.
|
|
Ignore session storage (ignore-session ) (v4.0.12+) |
Configure the tab interface to remain on the first or default selected tab on all page loads through the ignore-session class. |
Add ignore-session after the wb-tabs class.
|
|
Print only the active (visible) panel (print-active ) (v4.0.15+) |
Configure the tab interface to print only the active (visible) panel through the print-active class. |
Add print-active after the wb-tabs class.
|
|
Configuration options - Carousel only
Option | Description | How to configure | Values |
---|---|---|---|
Carousel style | Configures the carousel style. | Add the value after the wb-tabs class (e.g., class="wb-tabs carousel-s1" ) |
|
Change rotation speed (data-wb-tabs ) |
Configure the tab rotation speed through the interval property of the data-wb-tabs attribute. |
Add the data-wb-tabs attribute to the element with class="wb-tabs" and include the interval property with the number of seconds between tab rotations.
|
|
Change rotation speed (slow , fast ) |
Configure the tab rotation speed through either the slow or fast classes. |
Add either slow or fast after the wb-tabs class.
|
|
Tab panel transitions | Configure the tab panel transition type through the fade , slide or slidevert classes. |
Add fade , slide or slidevert after the in or out class on each tab panel.
|
|
Exclude play (data-wb-tabs ) (v4.0.5+) |
Exclude the play button from the carousel controls through the excludePlay property of the data-wb-tabs attribute. |
Add the data-wb-tabs attribute to the element with class="wb-tabs" and include the excludePlay property with true for the value.
|
|
Exclude play (exclude-play ) (v4.0.5+) |
Exclude the play button from the carousel controls through the exclude-play class. |
Add exclude-play after the wb-tabs class.
|
|
Play on page load (data-wb-tabs ) (v4.0.5+) |
Play the carousel on page load through the playing property of the data-wb-tabs attribute.Warning: Playing on page load can be distracting and cause usability issues for some users. Note: Playing will be disabled if the play button is excluded from the carousel controls. |
Add the data-wb-tabs attribute to the element with class="wb-tabs" and include the playing property with true for the value.
|
|
Play on page load (playing ) |
Play the carousel on page load through the playing class.Warning: Playing on page load can be distracting and cause usability issues for some users. Note: Playing will be disabled if the play button is excluded from the carousel controls. |
Add playing after the wb-tabs class.
|
|
Events
Event | Trigger | What it does |
---|---|---|
wb-init.wb-tabs | Triggered manually (e.g., $( ".wb-tabs" ).trigger( "wb-init.wb-tabs" ); ). |
Used to manually initialize the Tabbed interface plugin. Note: The Tabbed interface plugin will be initialized automatically unless the required markup is added after the page has already loaded. |
wb-ready.wb-tabs (v4.0.5+) |
Triggered automatically after a tabbed interface or carousel initializes. | Used to identify which tabbed interface or carousel was initialized (target of the event)
|
wb-updated.wb-tabs (v4.0.5+) |
Triggered automatically after a tabbed interface/carousel was updated (visible tab panel changed). | Used to identify which tabbed inteface/carousel was updated (target of the event) and to pass along the newly visible panel (as a jQuery object).
|
wb-shift.wb-tabs |
Triggered manually or automatically to change which tab panel is visible. | Changes which tab panel is visible. The value of shiftto is the number of tab panels to move forwards (positive number) or backwards (negative number).
|
wb-select.wb-tabs (v4.0.8+) |
Triggered manually or automatically to change which tab panel is visible. | Changes which tab panel is visible. The value of id is the id attribute of the tab panel to make visible.
|
wb-ready.wb (v4.0.5+) |
Triggered automatically when WET has finished loading and executing. | Used to identify when all WET plugins and polyfills have finished loading and executing.
|
Source code
- Date de modification :