Tabs are kind of like togglers, but only one tab is active at a time. When you enable the state of one tab, another tab is disabled.
data-ur-set="tabs"
data-ur-tabs-component="button"
data-ur-tabs-component="content"
data-ur-tab-id="NAME"
data-ur-set="tabs"
data-ur-closeable
: enabled/disabled (allow all tabs to be closed at the same time)
data-ur-tabs-component="button"
data-ur-tab-id
is required and must match the attribute on the content element
data-ur-tabs-component="content"
data-ur-tab-id
is required and must match the attribute on the button elementYou can also directly initialize the widget in JavaScript (components can be passed in as strings/elements/arrays):
Uranium.lib.tabs({ set: "#a", tabs: { tab1: { button: "#b", content: "#c" }, tab2: { button: "#d", content: "#e" } } }, { closeable: true // data-ur-* options });
<div data-ur-set="tabs"> <div data-ur-tabs-component="button" data-ur-tab-id="one" data-ur-state="enabled">First</div> <div data-ur-tabs-component="button" data-ur-tab-id="two">Second</div> <div data-ur-tabs-component="button" data-ur-tab-id="three">Third</div> <div data-ur-tabs-component="content" data-ur-tab-id="one" data-ur-state="enabled"> First tab content </div> <div data-ur-tabs-component="content" data-ur-tab-id="two"> Second tab content </div> <div data-ur-tabs-component="content" data-ur-tab-id="three"> Third tab content </div> </div>
/* Recommended SCSS Styling */ [data-ur-tabs-component="content"] { display: none; &[data-ur-state="enabled"] { display: block; } }
/* Recommended CSS Styling */ [data-ur-tabs-component="content"] { display: none; } [data-ur-tabs-component="content"][data-ur-state="enabled"] { display: block; }
Here, as proof of principle, we're putting the data-ur-state="enabled"
attribute on the second tab to illustrate that a different tab can be selected at the outset.
<div data-ur-set="tabs"> <div data-ur-tabs-component="button" data-ur-tab-id="first">First</div> <div data-ur-tabs-component="button" data-ur-tab-id="second" data-ur-state="enabled">Second</div> <div data-ur-tabs-component="button" data-ur-tab-id="third">Third</div> <div data-ur-tabs-component="content" data-ur-tab-id="first"> First tab content </div> <div data-ur-tabs-component="content" data-ur-tab-id="second" data-ur-state="enabled"> Second tab content </div> <div data-ur-tabs-component="content" data-ur-tab-id="third"> Third tab content </div> </div>
So far, we've set one of the tabs to be enabled at the start. However, this isn't strictly necessary. In the following example, we start out with no states defined, so all tabs start out closed.
The first tab we click on will be the first one to be "enabled". And we've set the attribute data-ur-closeable
to "enabled"
on this tab set to allow the accordian to be collapsed back to its original state by clicking again on the open tab.
<div data-ur-set="tabs" data-ur-closeable="enable"> <div data-ur-tabs-component="button" data-ur-tab-id="first">First</div> <div data-ur-tabs-component="content" data-ur-tab-id="first">Oh Uranium.</div> <div data-ur-tabs-component="button" data-ur-tab-id="second">Second</div> <div data-ur-tabs-component="content" data-ur-tab-id="second">You do nifty interactions.</div> <div data-ur-tabs-component="button" data-ur-tab-id="third">Third</div> <div data-ur-tabs-component="content" data-ur-tab-id="third">And you're performant.</div> </div>