2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10 <link rel=
"import" href=
"../polymer/polymer.html">
11 <link rel=
"import" href=
"../paper-styles/paper-styles.html">
14 `paper-toolbar` is a horizontal bar containing items that can be used for
15 label, navigation, search and actions. The items place inside the
16 `paper-toolbar` are projected into a `class="horizontal center layout"` container inside of
17 `paper-toolbar`'s Shadow DOM. You can use flex attributes to control the items'
23 <paper-icon-button icon="menu" on-tap="menuAction"></paper-icon-button>
24 <div class="title">Title</div>
25 <paper-icon-button icon="more-vert" on-tap="moreAction"></paper-icon-button>
28 `paper-toolbar` has a standard height, but can made be taller by setting `tall`
29 class on the `paper-toolbar`. This will make the toolbar 3x the normal height.
31 <paper-toolbar class="tall">
32 <paper-icon-button icon="menu"></paper-icon-button>
35 Apply `medium-tall` class to make the toolbar medium tall. This will make the
36 toolbar 2x the normal height.
38 <paper-toolbar class="medium-tall">
39 <paper-icon-button icon="menu"></paper-icon-button>
42 When `tall`, items can pin to either the top (default), middle or bottom. Use
43 `middle` class for middle content and `bottom` class for bottom content.
45 <paper-toolbar class="tall">
46 <paper-icon-button icon="menu"></paper-icon-button>
47 <div class="middle title">Middle Title</div>
48 <div class="bottom title">Bottom Title</div>
51 For `medium-tall` toolbar, the middle and bottom contents overlap and are
52 pinned to the bottom. But `middleJustify` and `bottomJustify` attributes are
53 still honored separately.
55 To make an element completely fit at the bottom of the toolbar, use `fit` along
58 <paper-toolbar class="tall">
59 <div id="progressBar" class="bottom fit"></div>
64 The following custom properties and mixins are available for styling:
66 Custom property | Description | Default
67 ----------------|-------------|----------
68 `--paper-toolbar-background` | Toolbar background color | `--default-primary-color`
69 `--paper-toolbar-color` | Toolbar foreground color | `--text-primary-color`
70 `--paper-toolbar` | Mixin applied to the toolbar | `{}`
74 `<paper-toolbar>` has `role="toolbar"` by default. Any elements with the class `title` will
75 be used as the label of the toolbar via `aria-labelledby`.
80 <dom-module id=
"paper-toolbar">
87 box-sizing: border-box;
88 -moz-box-sizing: border-box;
93 background: var(--paper-toolbar-background, --default-primary-color);
94 color: var(--paper-toolbar-color, --text-primary-color);
96 @apply(--paper-toolbar);
101 transition: height
0.18s ease-in;
104 :host(.medium-tall) {
116 pointer-events: none;
120 * TODO: Where should media query breakpoints live so they can be shared between elements?
123 @media (max-width:
639px) {
128 :host(.medium-tall) {
153 :host(.tall) #middleBar,
154 :host(.medium-tall) #middleBar {
155 -webkit-transform: translateY(
100%);
156 transform: translateY(
100%);
168 * make elements (e.g. buttons) respond to mouse/touch events
170 * `.toolbar-tools` disables touch events so multiple toolbars can stack and not
171 * absorb events. All children must have pointer events re-enabled to work as
174 .toolbar-tools
> ::content
> *:not([disabled]) {
175 pointer-events: auto;
178 .toolbar-tools
> ::content .title {
179 @apply(--paper-font-title);
180 @apply(--layout-flex);
182 pointer-events: none;
183 text-overflow: ellipsis;
188 * Polymer/polymer/issues/
1525
189 * --paper-font-title defines a `font-weight`
190 * let's override its value, but we need `important!`
191 * because all mixins are resolved in rule's selector that has higher precedence
192 * than the current selector.
194 font-weight:
400 !important;
198 * TODO: Refactor these selectors
201 .toolbar-tools
> ::content paper-icon-button[icon=menu] {
205 .toolbar-tools
> ::content
> .title,
206 .toolbar-tools
> ::content[
select=
".middle"]
> .title,
207 .toolbar-tools
> ::content[
select=
".bottom"]
> .title {
211 .toolbar-tools
> ::content
> paper-icon-button + .title,
212 .toolbar-tools
> ::content[
select=
".middle"] paper-icon-button + .title,
213 .toolbar-tools
> ::content[
select=
".bottom"] paper-icon-button + .title {
217 .toolbar-tools
> ::content
> .fit {
231 <div id=
"topBar" class$=
"[[_computeBarClassName(justify)]]">
232 <content select=
":not(.middle):not(.bottom)"></content>
235 <div id=
"middleBar" class$=
"[[_computeBarClassName(middleJustify)]]">
236 <content select=
".middle"></content>
239 <div id=
"bottomBar" class$=
"[[_computeBarClassName(bottomJustify)]]">
240 <content select=
".bottom"></content>
253 function classNames(obj
) {
255 for (var key
in obj
) {
256 if (obj
.hasOwnProperty(key
) && obj
[key
]) {
257 classNames
.push(key
);
261 return classNames
.join(' ');
275 * Controls how the items are aligned horizontally when they are placed
277 * Options are `start`, `center`, `end`, `justified` and `around`.
279 * @attribute bottomJustify
289 * Controls how the items are aligned horizontally.
290 * Options are `start`, `center`, `end`, `justified` and `around`.
302 * Controls how the items are aligned horizontally when they are placed
304 * Options are `start`, `center`, `end`, `justified` and `around`.
306 * @attribute middleJustify
317 attached: function() {
318 this._observer
= this._observe(this);
319 this._updateAriaLabelledBy();
322 detached: function() {
323 if (this._observer
) {
324 this._observer
.disconnect();
328 _observe: function(node
) {
329 var observer
= new MutationObserver(function() {
330 this._updateAriaLabelledBy();
332 observer
.observe(node
, {
339 _updateAriaLabelledBy: function() {
341 var contents
= Polymer
.dom(this.root
).querySelectorAll('content');
342 for (var content
, index
= 0; content
= contents
[index
]; index
++) {
343 var nodes
= Polymer
.dom(content
).getDistributedNodes();
344 for (var node
, jndex
= 0; node
= nodes
[jndex
]; jndex
++) {
345 if (node
.classList
&& node
.classList
.contains('title')) {
347 labelledBy
.push(node
.id
);
349 var id
= 'paper-toolbar-label-' + Math
.floor(Math
.random() * 10000);
356 if (labelledBy
.length
> 0) {
357 this.setAttribute('aria-labelledby', labelledBy
.join(' '));
361 _computeBarClassName: function(barJustify
) {
366 'toolbar-tools': true
369 // If a blank string or any falsy value is given, no other class name is
372 var justifyClassName
= (barJustify
=== 'justified') ?
374 barJustify
+ '-justified';
376 classObj
[justifyClassName
] = true;
379 return classNames(classObj
);