<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>TabView</title>
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=PT+Sans:400,700,400italic,700italic">
<link rel="stylesheet" href="../../build/cssgrids/cssgrids-min.css">
<link rel="stylesheet" href="../assets/css/main.css">
<link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
<link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
<script src="../../build/yui/yui-min.js"></script>
</head>
<body>
<!--
<a href="https://github.com/yui/yui3"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
-->
<div id="doc">
<div id="hd">
<h1><img src="http://yuilibrary.com/img/yui-logo.png"></h1>
</div>
<a href="#toc" class="jump">Jump to Table of Contents</a>
<h1>TabView</h1>
<div class="yui3-g">
<div class="yui3-u-3-4">
<div id="main">
<div class="content"><div class="intro">
<p>The TabView widget is a UI control that enables the user switch between content panels.</p>
</div>
<h2 id="getting-started">Getting Started</h2>
<p>
To include the source files for TabView and its dependencies, first load
the YUI seed file if you haven't already loaded it.
</p>
<pre class="code prettyprint"><script src="http://yui.yahooapis.com/3.10.3/build/yui/yui-min.js"></script></pre>
<p>
Next, create a new YUI instance for your application and populate it with the
modules you need by specifying them as arguments to the <code>YUI().use()</code> method.
YUI will automatically load any dependencies required by the modules you
specify.
</p>
<pre class="code prettyprint"><script>
// Create a new YUI instance and populate it with the required modules.
YUI().use('tabview', function (Y) {
// TabView is available and ready for use. Add implementation
// code here.
});
</script></pre>
<p>
For more information on creating YUI instances and on the
<a href="http://yuilibrary.com/yui/docs/api/classes/YUI.html#method_use"><code>use()</code> method</a>, see the
documentation for the <a href="../yui/index.html">YUI Global Object</a>.
</p>
<h2 id="anatomy">Anatomy of a TabView</h2>
<h3 id="minimum-markup-requirement">Minimum Markup Requirement</h3>
<p>
<strong>Note:</strong> be sure to add the <code>yui3-skin-sam</code> classname to the
page's <code><body></code> element or to a parent element of the widget in order to apply
the default CSS skin. See <a href="http://yuilibrary.com/yui/docs/tutorials/skins/">Understanding Skinning</a>.
</p>
<pre class="code prettyprint"><body class="yui3-skin-sam"> <!-- You need this skin class --></pre>
<p>A <code>TabView</code> consists of a list of links that target a content element.</p>
<p>The basic markup needed to create from HTML is the following:</p>
<pre class="code prettyprint"><div id="demo">
<ul>
<li><a href="#foo">foo</a></li>
<li><a href="#bar">bar</a></li>
<li><a href="#baz">baz</a></li>
</ul>
<div>
<div id="foo">foo content</div>
<div id="bar">bar content</div>
<div id="baz">baz content</div>
</div>
</div></pre>
<h3 id="rendered-markup">Rendered Markup</h3>
<p>After a <code>TabView</code> is rendered, the final markup becomes:
<pre class="code prettyprint"><div class="yui3-widget yui3-tabview">
<div id="demo" class="yui3-tabview-content">
<ul class="yui3-tabview-list">
<li class="yui3-tab yui3-widget yui3-tab-selected">
<a href="#foo" class="yui3-tab-label yui3-tab-content">foo</a>
</li>
<li class="yui3-tab yui3-widget">
<a href="#bar" class="yui3-tab-label yui3-tab-content">bar</a>
</li>
<li class="yui3-tab yui3-widget">
<a href="#baz" class="yui3-tab-label yui3-tab-content">baz</a>
</li>
</ul>
<div class="yui3-tabview-panel">
<div id="foo" class="yui3-tab-panel">foo content</div>
<div id="bar" class="yui3-tab-panel">bar content</div>
<div id="baz" class="yui3-tab-panel">baz content</div>
</div>
</div>
</div></pre>
<h2 id="instantiating">Creating and Configuring a TabView</h2>
<p>A <code>TabView</code> instance can be created from existing markup on the page, or dynamically
using JavaScript.</p>
<h3 id="from-markup">From Existing Markup</h3>
<p>To create from existing markup, first conform to the basic markup pattern, then create a
new <code>TabView</code> instance, pointing to the existing <code>srcNode</code>, and render.</p>
<pre class="code prettyprint"><div id="demo">
<ul>
<li><a href="#foo">foo</a></li>
<li><a href="#bar">bar</a></li>
<li><a href="#baz">baz</a></li>
</ul>
<div>
<div id="foo">foo content</div>
<div id="bar">bar content</div>
<div id="baz">baz content</div>
</div>
</div>
<script>
YUI().use('tabview', function(Y) {
var tabview = new Y.TabView({
srcNode: '#demo'
});
tabview.render();
});
</script></pre>
<h3 id="from-js">From JavaScript</h3>
<p>To create purely from JavaScript, all that is required is passing the <code>TabView</code>
constructor a list of <code>children</code> containing their respective <code>label</code>
and <content> attributes, and call render. As with all YUI <code>Widget</code>s,
render takes an optional container to render into, or defaults to the <code>body</code> element.</p>
<pre class="code prettyprint"><div id="demo"></div>
<script>
YUI().use('tabview', function(Y) {
var tabview = new Y.TabView({
children: [{
label: 'foo',
content: '<p>foo content</p>'
}, {
label: 'bar',
content: '<p>bar content</p>'
}, {
label: 'baz',
content: '<p>baz content</p>'
}]
});
tabview.render('#demo');
});
</script></pre>
<h2 id="skinning">Skinning TabView</h2>
<p>The <code>TabView</code> comes with a basic skin by default. This can be easily
customized using the rich set of <a href="#rendered-markup">classNames</a>.</p>
<p>For a more polished look and feel, we also ship with the "sam skin", which can
be applied by adding the <code>yui3-skin-sam</code> className to some ancestor:</p>
<pre class="code prettyprint"><body class="yui3-skin-sam">
...
<div id="demo">
<ul>
<li><a href="#foo">foo</a></li>
<li><a href="#bar">bar</a></li>
<li><a href="#baz">baz</a></li>
</ul>
<div>
<div id="foo">foo content</div>
<div id="bar">bar content</div>
<div id="baz">baz content</div>
</div>
</div>
...
</body></pre>
<h2 id="events">TabView Events</h2>
<p>TabViews fire the following events during operation:</p>
<table>
<thead>
<tr>
<th>Event</th>
<th>When</th>
<th>Payload</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>addChild</code></td>
<td>a Tab is added to the TabView</td>
<td><code>child, index</code></td>
</tr>
<tr>
<td><code>removeChild</code></td>
<td>a Tab is removed from the TabView</td>
<td><code>child, index</code></td>
</tr>
<tr>
<td><code>selectionChange</code></td>
<td>the selected tab changes</td>
<td><code>prevVal, newVal</code></td>
</tr>
<tr>
<td><code>render</code></td>
<td>a Tabview is rendered</td>
<td>Normal change event signature (<code>newVal</code>, <code>prevVal</code>, etc). When dragging, extra event property <code>ddEvent : (drag:drag event)</code> is added</td>
</tr>
</tbody>
</table>
<p>This is not an exhaustive list. See the <a href="http://yuilibrary.com/yui/docs/api/module_tabview.html">API docs</a> for a complete listing.</p>
</div>
</div>
</div>
<div class="yui3-u-1-4">
<div class="sidebar">
<div id="toc" class="sidebox">
<div class="hd">
<h2 class="no-toc">Table of Contents</h2>
</div>
<div class="bd">
<ul class="toc">
<li>
<a href="#getting-started">Getting Started</a>
</li>
<li>
<a href="#anatomy">Anatomy of a TabView</a>
<ul class="toc">
<li>
<a href="#minimum-markup-requirement">Minimum Markup Requirement</a>
</li>
<li>
<a href="#rendered-markup">Rendered Markup</a>
</li>
</ul>
</li>
<li>
<a href="#instantiating">Creating and Configuring a TabView</a>
<ul class="toc">
<li>
<a href="#from-markup">From Existing Markup</a>
</li>
<li>
<a href="#from-js">From JavaScript</a>
</li>
</ul>
</li>
<li>
<a href="#skinning">Skinning TabView</a>
</li>
<li>
<a href="#events">TabView Events</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="This example shows how to create a TabView wigdet from existing HTML.">
<a href="tabview-basic.html">TabView from Existing Markup</a>
</li>
<li data-description="This example shows how to create a TabView wigdet from JavaScript.">
<a href="tabview-fromjs.html">Dynamic TabView from JavaScript</a>
</li>
<li data-description="This example shows how to add and remove Tabs.">
<a href="tabview-add-remove.html">Adding and Removing Tabs</a>
</li>
<li data-description="This example shows how to load tab content remotely using a YQL plugin.">
<a href="tabview-yql.html">Loading Tab Content</a>
</li>
</ul>
</div>
</div>
<div class="sidebox">
<div class="hd">
<h2 class="no-toc">Examples That Use This Component</h2>
</div>
<div class="bd">
<ul class="examples">
<li data-description="Demonstrates how to add browser history support to a TabView widget using the History Utility.">
<a href="../history/history-tabview.html">History + TabView</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script>prettyPrint();</script>
<script>
YUI.Env.Tests = {
examples: [],
project: '../assets',
assets: '../assets/tabview',
name: 'tabview',
title: 'TabView',
newWindow: '',
auto: false
};
YUI.Env.Tests.examples.push('tabview-basic');
YUI.Env.Tests.examples.push('tabview-fromjs');
YUI.Env.Tests.examples.push('tabview-add-remove');
YUI.Env.Tests.examples.push('tabview-yql');
YUI.Env.Tests.examples.push('history-tabview');
</script>
<script src="../assets/yui/test-runner.js"></script>
</body>
</html>