ons-toolbar

Toolbar component that can be used with navigation. Left, center and right containers can be specified by class names. This component will automatically display as a Material Design toolbar when running on Android devices.

Tutorial

Adding a toolbar

Most mobile apps have a toolbar at the top containing a header text and maybe some buttons.

In Onsen UI this is achieved using the <ons-toolbar> element. It is divided into three sections that are defined using the HTML classes left, center and right.

<ons-toolbar>
  <div class="left">
    Left part
  </div>
  <div class="center">
    Title here
  </div>
  <div class="right">
    Right part
  </div>
</ons-toolbar>

Buttons can be added to the toolbar with the <ons-toolbar-button> element.

Inline and static toolbars

We can indicate that the toolbar should be part of the scrollable content with the inline attribute.

Additionally, the static attribute prevents the toolbar from being animated in some navigator animations to enhance performance.

Compilation

ons-toolbar divides its layout in three parts: div.left, div.center and div.right. However, these classes are simple aliases for the real classes. A normal toolbar will compile its content as follows:

<ons-toolbar class="toolbar">
  <div class="left toolbar__left">Left content</div>
  <div class="center toolbar__center">Center content</div>
  <div class="right toolbar__right">Right content</div>
</ons-toolbar>

In addition, these containers are sorted automatically to always match “left - center - right” order.

See also

Attributes are added directly to the element. You can do this in HTML or JS.

HTML: <ons-toolbar someAttribute="true" anotherAttribute><ons-toolbar>
JS: document.querySelector('ons-toolbar').setAttribute('someAttribute', 'true')

Name Type Description
inline Display the toolbar as an inline element. Optional. Works only during initialization.
static Static toolbars are not animated by ons-navigator when pushing or popping pages. This can be useful to improve performance in some situations. Optional.
modifier The appearance of the toolbar. Optional.

Properties are accessed on the element through JS, and should be get and set directly. For example: document.querySelector('ons-toolbar').static.

Name Description
static Static toolbars are not animated by ons-navigator when pushing or popping pages. This can be useful to improve performance in some situations.
visible Whether the toolbar is shown or not.

Modifiers are set in the modifier attribute. To use more than one, separate them by spaces. For example:
<ons-toolbar modifier="material transparent"><ons-toolbar>.

Name Description
material Material Design toolbar.
transparent Transparent toolbar.
cover-content Displays the toolbar on top of the page’s content. Should be combined with transparent modifier.
noshadow Toolbar without shadow.

These methods are called directly on the DOM element. Get a reference to the element in JS, and the methods below will be available to call on it. For example: document.querySelector('ons-toolbar').someMethod().

Signature Description
setVisibility(visible) Shows the toolbar if visible is true, otherwise hides it.
show() Show the toolbar.
hide() Hide the toolbar.
setVisibility(visible)

Shows the toolbar if visible is true, otherwise hides it.

Parameters
Name Type Description
visible Boolean Set to true to show the toolbar, false to hide it
show()

Show the toolbar.

hide()

Hide the toolbar.

Need Help?

If you have any questions, use our Community Forum or talk to us on Discord chat. The Onsen UI team and your peers in the community will work together to help solve your issues.

For bug reports and feature requests use our GitHub Issues page.