blob: 94adf32dcede0358a608015d71b0258ff38b762f [file] [log] [blame]
<h2 id="introduction">Introduction</h2>
<p>The Material Design Lite (MDL) <strong>tab</strong> component is a user interface element that allows different content blocks to share the same screen space in a mutually exclusive manner. Tabs are always presented in sets of two or more, and they make it easy to explore and switch among different views or functional aspects of an app, or to browse categorized data sets individually. Tabs serve as &quot;headings&quot; for their respective content; the <em>active</em> tab &mdash; the one whose content is currently displayed &mdash; is always visually distinguished from the others so the user knows which heading the current content belongs to.</p>
<p>Tabs are an established but non-standardized feature in user interfaces, and allow users to view different, but often related, blocks of content (often called <em>panels</em>). Tabs save screen real estate and provide intuitive and logical access to data while reducing navigation and associated user confusion. Their design and use is an important factor in the overall user experience. See the tab component&#39;s <a href="http://www.google.com/design/spec/components/tabs.html">Material Design specifications page</a> for details.</p>
<h3 id="to-include-a-set-of-mdl-tab-components-">To include a set of MDL <strong>tab</strong> components:</h3>
<p>&nbsp;1. Code a <code>&lt;div&gt;</code> element; this is the &quot;outer&quot; div, intended to contain all of the tabs and their content.</p>
<pre><code class="lang-html">&lt;div&gt;
&lt;/div&gt;
</code></pre>
<p>&nbsp;2. Inside the &quot;outer&quot; div, code one &quot;inner&quot; div for the tabs themselves, and one for each tab&#39;s content, all siblings. That is, for three content tabs, you would code four &quot;inner&quot; divs.</p>
<pre><code class="lang-html">&lt;div&gt;
&lt;div&gt;
...
&lt;/div&gt;
&lt;div&gt;
...
&lt;/div&gt;
&lt;div&gt;
...
&lt;/div&gt;
&lt;div&gt;
...
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>&nbsp;3. Inside the first &quot;inner&quot; div (the tabs), code one anchor <code>&lt;a&gt;</code> (link) tag for each tab. Include <code>href</code> attributes with values to match the tabs&#39; <code>id</code> attribute values, and some brief link text. On the remaining &quot;inner&quot; divs (the content), code <code>id</code> attributes whose values match the links&#39; <code>href</code>s.</p>
<pre><code class="lang-html">&lt;div&gt;
&lt;div&gt;
&lt;a href=&quot;#tab1&quot;&gt;Tab One&lt;/a&gt;
&lt;a href=&quot;#tab2&quot;&gt;Tab Two&lt;/a&gt;
&lt;a href=&quot;#tab3&quot;&gt;Tab Three&lt;/a&gt;
&lt;/div&gt;
&lt;div id=&quot;tab1&quot;&gt;
...
&lt;/div&gt;
&lt;div id=&quot;tab2&quot;&gt;
...
&lt;/div&gt;
&lt;div id=&quot;tab3&quot;&gt;
...
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>&nbsp;4. Inside the remaining &quot;inner&quot; divs, code the content you intend to display in each panel; use standard HTML tags to structure the content as desired.</p>
<pre><code class="lang-html">&lt;div&gt;
&lt;div&gt;
&lt;a href=&quot;#tab1&quot;&gt;Tab One&lt;/a&gt;
&lt;a href=&quot;#tab2&quot;&gt;Tab Two&lt;/a&gt;
&lt;a href=&quot;#tab3&quot;&gt;Tab Three&lt;/a&gt;
&lt;/div&gt;
&lt;div id=&quot;tab1&quot;&gt;
&lt;p&gt;First tab&#39;s content.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&quot;tab2&quot;&gt;
&lt;p&gt;Second tab&#39;s content.&lt;/p&gt;
&lt;/div&gt;
&lt;div id=&quot;tab3&quot;&gt;
&lt;p&gt;Third tab&#39;s content.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>&nbsp;5. Add one or more MDL classes, separated by spaces, to the &quot;outer&quot; and &quot;inner&quot; divs using the <code>class</code> attribute; be sure to include the <code>is-active</code> class on the tab you want to be displayed by default.</p>
<pre><code class="lang-html">&lt;div class=&quot;mdl-tabs mdl-js-tabs&quot;&gt;
&lt;div class=&quot;mdl-tabs__tab-bar&quot;&gt;
&lt;a href=&quot;#tab1&quot; class=&quot;mdl-tabs__tab&quot;&gt;Tab One&lt;/a&gt;
&lt;a href=&quot;#tab2&quot; class=&quot;mdl-tabs__tab&quot;&gt;Tab Two&lt;/a&gt;
&lt;a href=&quot;#tab3&quot; class=&quot;mdl-tabs__tab&quot;&gt;Tab Three&lt;/a&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-tabs__panel is-active&quot; id=&quot;tab1&quot;&gt;
&lt;p&gt;First tab&#39;s content.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-tabs__panel&quot; id=&quot;tab2&quot;&gt;
&lt;p&gt;Second tab&#39;s content.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-tabs__panel&quot; id=&quot;tab3&quot;&gt;
&lt;p&gt;Third tab&#39;s content.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<p>The tab components are ready for use.</p>
<h4 id="example">Example</h4>
<p>Three tabs, with ripple effect on tab links.</p>
<pre><code class="lang-html">&lt;div class=&quot;mdl-tabs mdl-js-tabs mdl-js-ripple-effect&quot;&gt;
&lt;div class=&quot;mdl-tabs__tab-bar&quot;&gt;
&lt;a href=&quot;#about-panel&quot; class=&quot;mdl-tabs__tab is-active&quot;&gt;About the Beatles&lt;/a&gt;
&lt;a href=&quot;#members-panel&quot; class=&quot;mdl-tabs__tab&quot;&gt;Members&lt;/a&gt;
&lt;a href=&quot;#albums-panel&quot; class=&quot;mdl-tabs__tab&quot;&gt;Discography&lt;/a&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-tabs__panel is-active&quot; id=&quot;about-panel&quot;&gt;
&lt;p&gt;&lt;b&gt;The Beatles&lt;/b&gt; were a four-piece musical group from Liverpool, England.
Formed in 1960, their career spanned just over a decade, yet they are widely
regarded as the most influential band in history.&lt;/p&gt;
&lt;p&gt;Their songs are among the best-loved music of all time. It is said that every
minute of every day, a radio station somewhere is playing a Beatles song.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-tabs__panel&quot; id=&quot;members-panel&quot;&gt;
&lt;p&gt;The Beatles&#39; members were:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;John Lennon (1940-1980)&lt;/li&gt;
&lt;li&gt;Paul McCartney (1942-)&lt;/li&gt;
&lt;li&gt;George Harrison (1943-2001)&lt;/li&gt;
&lt;li&gt;Ringo Starr (1940-)&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;div class=&quot;mdl-tabs__panel&quot; id=&quot;albums-panel&quot;&gt;
&lt;p&gt;The Beatles&#39; original UK LPs, in order of release:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Please Please Me (1963)&lt;/li&gt;
&lt;li&gt;With the Beatles (1963)&lt;/li&gt;
&lt;li&gt;A Hard Day&#39;s Night (1964)&lt;/li&gt;
&lt;li&gt;Beatles for Sale (1964)&lt;/li&gt;
&lt;li&gt;Help! (1965)&lt;/li&gt;
&lt;li&gt;Rubber Soul (1965)&lt;/li&gt;
&lt;li&gt;Revolver (1966)&lt;/li&gt;
&lt;li&gt;Sgt. Pepper&#39;s Lonely Hearts Club Band (1967)&lt;/li&gt;
&lt;li&gt;The Beatles (&quot;The White Album&quot;, 1968)&lt;/li&gt;
&lt;li&gt;Yellow Submarine (1969)&lt;/li&gt;
&lt;li&gt;Abbey Road (1969)&lt;/li&gt;
&lt;li&gt;Let It Be (1970)&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>
<h2 id="configuration-options">Configuration options</h2>
<p>The MDL CSS classes apply various predefined visual and behavioral enhancements to the tabs. The table below lists the available classes and their effects.</p>
<table>
<thead>
<tr>
<th>MDL class</th>
<th>Effect</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>mdl-tabs</code></td>
<td>Defines a tabs container as an MDL component</td>
<td>Required on &quot;outer&quot; div element</td>
</tr>
<tr>
<td><code>mdl-js-tabs</code></td>
<td>Assigns basic MDL behavior to tabs container</td>
<td>Required on &quot;outer&quot; div element</td>
</tr>
<tr>
<td><code>mdl-js-ripple-effect</code></td>
<td>Applies <em>ripple</em> click effect to tab links</td>
<td>Optional; goes on &quot;outer&quot; div element</td>
</tr>
<tr>
<td><code>mdl-tabs__tab-bar</code></td>
<td>Defines a container as an MDL tabs link bar</td>
<td>Required on first &quot;inner&quot; div element</td>
</tr>
<tr>
<td><code>mdl-tabs__tab</code></td>
<td>Defines an anchor (link) as an MDL tab activator</td>
<td>Required on all links in first &quot;inner&quot; div element</td>
</tr>
<tr>
<td><code>is-active</code></td>
<td>Defines a tab as the default display tab</td>
<td>Required on one (and only one) of the &quot;inner&quot; div (tab) elements</td>
</tr>
<tr>
<td><code>mdl-tabs__panel</code></td>
<td>Defines a container as tab content</td>
<td>Required on each of the &quot;inner&quot; div (tab) elements</td>
</tr>
</tbody>
</table>