Tabs Widgetversion added: 1.0
Description: A single content area with multiple panels, each associated with a header in a list.
Tabs are generally used to break content into multiple sections that can be swapped to save space, much like an accordion.
Tabs have a particular set of markup that must be used in order for them to work properly:
- The tabs themselves must be in either an ordered (
<ol>
) or unordered (<ul>
) list - Each tab "title" must be inside of a list item (
<li>
) and wrapped by an anchor (<a>
) with anhref
attribute - Each tab panel may be any valid element but it must have an id which corresponds to the hash in the anchor of the associated tab.
The content for each tab panel can be defined in-page or can be loaded via Ajax; both are handled automatically based on the href
of the anchor associated with the tab. By default tabs are activated on click, but the events can be changed to hover via the event
option.
Below is some sample markup:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
|
Keyboard interaction
When focus is on a tab, the following key commands are available:
- UP/LEFT: Move focus to the previous tab. If on first tab, moves focus to last tab. Activate focused tab after a short delay.
- DOWN/RIGHT: Move focus to the next tab. If on last tab, moves focus to first tab. Activate focused tab after a short delay.
- HOME: Move focus to the first tab. Activate focused tab after a short delay.
- END: Move focus to the last tab. Activate focused tab after a short delay.
- SPACE: Activate panel associated with focused tab.
- ENTER: Activate or toggle panel associated with focused tab.
- ALT+PAGE UP: Move focus to the previous tab and immediately activate.
- ALT+PAGE DOWN: Move focus to the next tab and immediately activate.
When focus is in a panel, the following key commands are available:
- CTRL+UP: Move focus to associated tab.
- ALT+PAGE UP: Move focus to the previous tab and immediately activate.
- ALT+PAGE DOWN: Move focus to the next tab and immediately activate.
Theming
The tabs widget uses the jQuery UI CSS framework to style its look and feel. If tabs specific styling is needed, the following CSS class names can be used:
-
ui-tabs
: The outer container of the tabs. This element will additionally have a class ofui-tabs-collapsible
when thecollapsible
option is set.-
ui-tabs-nav
: The list of tabs.- The active list item in the nav will have a
ui-tabs-active
class. Any list item whose associated content is loading via an Ajax call will have aui-tabs-loading
class.-
ui-tabs-anchor
: The anchors used to switch panels.
-
- The active list item in the nav will have a
-
ui-tabs-panel
: The panels associated with the tabs. Only the panel whose corresponding tab is active will be visible.
-
Dependencies
- UI Core
- Widget Factory
-
Effects Core (optional; for use with the
show
andhide
options)
Additional Notes:
- This widget requires some functional CSS, otherwise it won't work. If you build a custom theme, use the widget's specific CSS file as a starting point.
Options
active
0
-
Boolean: Setting
active
tofalse
will collapse all panels. This requires thecollapsible
option to betrue
. - Integer: The zero-based index of the panel that is active (open). A negative value selects panels going backward from the last panel.
Initialize the tabs with the active
option specified:
1
2
3
|
|
Get or set the active
option, after initialization:
1
2
3
4
5
|
|
collapsible
false
true
, the active panel can be closed.Initialize the tabs with the collapsible
option specified:
1
2
3
|
|
Get or set the collapsible
option, after initialization:
1
2
3
4
5
|
|
disabled
false
- Boolean: Enable or disable all tabs.
-
Array: An array containing the zero-based indexes of the tabs that should be disabled, e.g.,
[ 0, 2 ]
would disable the first and third tab.
Initialize the tabs with the disabled
option specified:
1
2
3
|
|
Get or set the disabled
option, after initialization:
1
2
3
4
5
|
|
event
"click"
"mouseover"
.Initialize the tabs with the event
option specified:
1
2
3
|
|
Get or set the event
option, after initialization:
1
2
3
4
5
|
|
heightStyle
"content"
-
"auto"
: All panels will be set to the height of the tallest panel. -
"fill"
: Expand to the available height based on the tabs' parent height. -
"content"
: Each panel will be only as tall as its content.
Initialize the tabs with the heightStyle
option specified:
1
2
3
|
|
Get or set the heightStyle
option, after initialization:
1
2
3
4
5
|
|
hide
null
-
Boolean:
When set to
false
, no animation will be used and the panel will be hidden immediately. When set totrue
, the panel will fade out with the default duration and the default easing. - Number: The panel will fade out with the specified duration and the default easing.
-
String:
The panel will be hidden using the specified effect.
The value can either be the name of a built-in jQuery animation method, such as
"slideUp"
, or the name of a jQuery UI effect, such as"fold"
. In either case the effect will be used with the default duration and the default easing. -
Object: If the value is an object, then
effect
,delay
,duration
, andeasing
properties may be provided. If theeffect
property contains the name of a jQuery method, then that method will be used; otherwise it is assumed to be the name of a jQuery UI effect. When using a jQuery UI effect that supports additional settings, you may include those settings in the object and they will be passed to the effect. Ifduration
oreasing
is omitted, then the default values will be used. Ifeffect
is omitted, then"fadeOut"
will be used. Ifdelay
is omitted, then no delay is used.
Initialize the tabs with the hide
option specified:
1
2
3
|
|
Get or set the hide
option, after initialization:
1
2
3
4
5
|
|
show
null
-
Boolean:
When set to
false
, no animation will be used and the panel will be shown immediately. When set totrue
, the panel will fade in with the default duration and the default easing. - Number: The panel will fade in with the specified duration and the default easing.
-
String:
The panel will be shown using the specified effect.
The value can either be the name of a built-in jQuery animation method, such as
"slideDown"
, or the name of a jQuery UI effect, such as"fold"
. In either case the effect will be used with the default duration and the default easing. -
Object: If the value is an object, then
effect
,delay
,duration
, andeasing
properties may be provided. If theeffect
property contains the name of a jQuery method, then that method will be used; otherwise it is assumed to be the name of a jQuery UI effect. When using a jQuery UI effect that supports additional settings, you may include those settings in the object and they will be passed to the effect. Ifduration
oreasing
is omitted, then the default values will be used. Ifeffect
is omitted, then"fadeIn"
will be used. Ifdelay
is omitted, then no delay is used.
Initialize the tabs with the show
option specified:
1
2
3
|
|
Get or set the show
option, after initialization:
1
2
3
4
5
|
|
Methods
destroy()Returns: jQuery (plugin only)
- This method does not accept any arguments.
Invoke the destroy method:
1
|
|
disable()Returns: jQuery (plugin only)
- This signature does not accept any arguments.
Invoke the method:
1
|
|
disable( index )Returns: jQuery (plugin only)
disabled
option: $( "#tabs" ).tabs( "option", "disabled", [ 1, 2, 3 ] )
.
-
indexWhich tab to disable.
Invoke the method:
1
|
|
enable()Returns: jQuery (plugin only)
- This signature does not accept any arguments.
Invoke the method:
1
|
|
enable( index )Returns: jQuery (plugin only)
$( "#example" ).tabs( "option", "disabled", [] );
.-
indexWhich tab to enable.
Invoke the method:
1
|
|
load( index )Returns: jQuery (plugin only)
-
indexWhich tab to load.
Invoke the load method:
1
|
|
option( optionName )Returns: Object
optionName
.-
optionNameType: StringThe name of the option to get.
Invoke the method:
1
|
|
option()Returns: PlainObject
- This signature does not accept any arguments.
Invoke the method:
1
|
|
option( optionName, value )Returns: jQuery (plugin only)
optionName
.-
optionNameType: StringThe name of the option to set.
-
valueType: ObjectA value to set for the option.
Invoke the method:
1
|
|
option( options )Returns: jQuery (plugin only)
-
optionsType: ObjectA map of option-value pairs to set.
Invoke the method:
1
|
|
refresh()Returns: jQuery (plugin only)
heightStyle
option.- This method does not accept any arguments.
Invoke the refresh method:
1
|
|
widget()Returns: jQuery
jQuery
object containing the tabs container.
- This method does not accept any arguments.
Invoke the widget method:
1
|
|
Extension Points
The tabs widget is built with the widget factory and can be extended. When extending widgets, you have the ability to override or add to the behavior of existing methods. The following methods are provided as extension points with the same API stability as the plugin methods listed above. For more information on widget extensions, see Extending Widgets with the Widget Factory.
_getList()Returns: jQuery
- This method does not accept any arguments.
Use the list with the class my-tabs
or fall back to the default implementation.
1
2
3
4
|
|
Events
activate( event, ui )Type: tabsactivate
Triggered after a tab has been activated (after animation completes). If the tabs were previously collapsed, ui.oldTab
and ui.oldPanel
will be empty jQuery objects. If the tabs are collapsing, ui.newTab
and ui.newPanel
will be empty jQuery objects.
activate
event is only fired on tab activation, it is not fired for the initial tab when the tabs widget is created. If you need a hook for widget creation use the create
event.Initialize the tabs with the activate callback specified:
1
2
3
|
|
Bind an event listener to the tabsactivate event:
1
|
|
beforeActivate( event, ui )Type: tabsbeforeactivate
ui.oldTab
and ui.oldPanel
will be empty jQuery objects. If the tabs are collapsing, ui.newTab
and ui.newPanel
will be empty jQuery objects.Initialize the tabs with the beforeActivate callback specified:
1
2
3
|
|
Bind an event listener to the tabsbeforeactivate event:
1
|
|
beforeLoad( event, ui )Type: tabsbeforeload
Triggered when a remote tab is about to be loaded, after the beforeActivate
event. Can be canceled to prevent the tab panel from loading content; though the panel will still be activated. This event is triggered just before the Ajax request is made, so modifications can be made to ui.jqXHR
and ui.ajaxSettings
.
Note: Although ui.ajaxSettings
is provided and can be modified, some of these settings have already been processed by jQuery. For example, prefilters have been applied, data
has been processed, and type
has been determined. The beforeLoad
event occurs at the same time, and therefore has the same restrictions, as the beforeSend
callback from jQuery.ajax()
.
-
eventType: Event
-
uiType: Object
-
tabType: jQueryThe tab that is being loaded.
-
panelType: jQueryThe panel which will be populated by the Ajax response.
-
jqXHRType: jqXHRThe
jqXHR
object that is requesting the content. -
ajaxSettingsType: ObjectThe settings that will be used by
jQuery.ajax
to request the content.
-
Initialize the tabs with the beforeLoad callback specified:
1
2
3
|
|
Bind an event listener to the tabsbeforeload event:
1
|
|
create( event, ui )Type: tabscreate
ui.tab
and ui.panel
will be empty jQuery objects.Initialize the tabs with the create callback specified:
1
2
3
|
|
Bind an event listener to the tabscreate event:
1
|
|
load( event, ui )Type: tabsload
Initialize the tabs with the load callback specified:
1
2
3
|
|
Bind an event listener to the tabsload event:
1
|
|
Example:
A simple jQuery UI Tabs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
|