Yahoo! makes it easy to create an accessible, handsome tabbed interface. I used their Tab View library to create the tabbed search form for V3GGIE.com. While Tab View can create the tabbed content dynamically, I’m using it to hide/show hard-coded individual forms.
Step 1. Create the basic HTML code.
The tabbed code is a simple pattern:
- Start with a parent div and give it an id and class=”yui-navset”.
- Create an unordered list inside this div with class=”yui-nav”.
- Each list includes a deep link to a corresponding div that is also a child of the parent div. The link text in an em tag.
- V3GGIE Search
- Create a div with class=”yui-content” and create a set of content containing divs. Each div has an id.
- Insert the Tabview CSS at the top of the page, the Tab View JS at the bottom of the page, create a small js that instantiates the tab-view module.
- For easier styling, use the sam_skin CSS package and add class=”yui-skin-sam” to the body.
Step 2. Use PHP to make it more interesting
Each page calls this chunk of code to insert the tabbed form, it also sets a variable ($selected), determining which tab is selected on page load. I’m also inserting the last search query into the text input to make it easier on the user. This is easily done by grabbing the query from the Request object.
The finished code:
The Final Product
We now have a tabbed module that allows the user to find recipes, news, blogs, and local restaurants from any page. This is an easy introduction to the YUI libraries. However, I came across the following surprises:
- The order of the tabs must match the order of the target divs. I moved my tabs around and discovered they were toggling the wrong forms.
- The links that generate the tabs need to have em tags surrounding the text
- You’ll need to download the entire YUI package to gain access to the CSS and sprites needed for the library. The examples on the YUI site assume relative links to files, you will either need to duplicate that file structure or upload the skin’s sprite and change the CSS accordingly.