TopBar
Provides tabs for navigation and buttons for contextual actions.
Beware that this API will be replaced be the
ts.ui.Header
in a future release.
If you plan to make use of the TopBar, we suggest that you give it a descriptive title.
— because even when the title is hidden by the tabs, like on this page, it will become visible when you resize to mobile breakpoint. The title also functions to show the TopBar on page load, so that it doesn't suddenly appear when you add buttons later.
TopBar.tabs
We can initialize the TopBar tabs with the the
tabs
method.
— but since the page already has tabs, we will instead append a new tab to the existing collection. If you omit the argument, you"ll get the current tabs (jQuery style).
You can use array methods like push
, pop
, shift
,
unshift
, splice
and so on to manage tabs, just note that the
tabs length
is a readonly property. Also note that tabs don"t do anything by
default, so what happens at onselect
is completely up to you.
Updating tabs
We can at any time change what happens when a tab gets selected. We can also change the tab label if we like, although maybe this would be confusing for the user.
Selecting tabs
We can programatically select a tab using one of these approaches.
Querying tabs
This will all become a lot easier if we give all the tabs an
id
and use
tabs.get()
Tabs icons
You can add a tab with an icon if somehow that tab is special.
Tab counters
You can add a counter to the tabs for whatever reason you like.
When the counter reaches zero, it disappears.
Closeable tabs
You can create closeable tabs, but note that the tab must be selected before it can be
closed. You can return false
in the onclose
method to prevent
the tab from closing (if this would otherwise cause data loss).
New-Tab button
You can allow the user to create new tabs via a special button as seen in popular
browsers. Note that the button just triggers a callback and that the new tab must be
created manually. In the example below, the
selected
property also selects the tab.
If you regret this later on, you can also hide the button.
Here"s a summary of the tabs
collection and tab
model.
TopBar.buttons
TopBar Back & Forward
The TopBar features both Back and Forward buttons for use in "drill down" scenarios.
You can also hide the Back and Forward buttons. Since the buttons obscure the tabs, you might actually like to do that now.
Note that tabbed navigation is not supposed to coexist with Back and Forward buttons.
Hide & show the TopBar
You can hide the TopBar — but not in mobile breakpoint, see below. Note that this operation will clear the contents of the TopBar.
You can also show it again. Because the content was cleared, we'll also restore it.
When you resize the window to mobile breakpoint, the hidden TopBar will be shown again automatically. That's because the TopBar is used to access the main navigation. Without the TopBar, you would be stuck in the app forever. But since you chose to hide the TopBar, we can assume that the content of the TopBar is not relevant. Therefore:
Since we don't want to show an outdated TopBar to mobile users, the content of the TopBar will be cleared when you hide it. To restore the old content, you will simply have to populate the TopBar again.
If you don't want your app to feature a TopBar under any circumstance, you can simply
remove the whole
<div data-ts="TopBar">
from the HTML.
TopBar summary
Here's a summary of the TopBar methods, including some bonus not yet discussed.
If you find a bug or need a feature…