paper-submenu.html
5.4 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
<!--
@license
Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="../iron-menu-behavior/iron-menu-behavior.html">
<link rel="import" href="../iron-behaviors/iron-control-state.html">
<link rel="import" href="../iron-collapse/iron-collapse.html">
<link rel="import" href="../paper-styles/paper-styles.html">
<!--
`<paper-submenu>` is a nested menu inside of a parent `<paper-menu>`. It
consists of a trigger that expands or collapses another `<paper-menu>`:
<paper-menu>
<paper-submenu>
<paper-item class="menu-trigger">Topics</paper-item>
<paper-menu class="menu-content">
<paper-item>Topic 1</paper-item>
<paper-item>Topic 2</paper-item>
<paper-item>Topic 3</paper-item>
</paper-menu>
</paper-submenu>
<paper-submenu>
<paper-item class="menu-trigger">Faves</paper-item>
<paper-menu class="menu-content">
<paper-item>Fave 1</paper-item>
<paper-item>Fave 2</paper-item>
</paper-menu>
</paper-submenu>
<paper-submenu disabled>
<paper-item class="menu-trigger">Unavailable</paper-item>
<paper-menu class="menu-content">
<paper-item>Disabled 1</paper-item>
<paper-item>Disabled 2</paper-item>
</paper-menu>
</paper-submenu>
</paper-menu>
Just like in `<paper-menu>`, the focused item is highlighted, and the selected
item has bolded text. Please see the `<paper-menu>` docs for which attributes
(such as `multi` and `selected`), and styling options are available for the
`menu-content` menu.
@group Paper Elements
@element paper-submenu
@hero hero.svg
@demo demo/index.html
-->
<dom-module id="paper-submenu">
<link rel="import" type="css" href="paper-menu-shared.css">
<template>
<div class="selectable-content" on-tap="_onTap">
<content id="trigger" select=".menu-trigger"></content>
</div>
<iron-collapse id="collapse" opened="{{opened}}">
<content select=".menu-content"></content>
</iron-collapse>
</template>
</dom-module>
<script>
(function() {
Polymer({
is: 'paper-submenu',
properties: {
/**
* Fired when the submenu is opened.
*
* @event paper-submenu-open
*/
/**
* Fired when the submenu is closed.
*
* @event paper-submenu-close
*/
/**
* Set opened to true to show the collapse element and to false to hide it.
*
* @attribute opened
*/
opened: {
type: Boolean,
value: false,
notify: true,
observer: '_openedChanged'
}
},
behaviors: [
Polymer.IronControlState
],
get __parent() {
return Polymer.dom(this).parentNode;
},
get __trigger() {
return Polymer.dom(this.$.trigger).getDistributedNodes()[0];
},
attached: function() {
this.listen(this.__parent, 'iron-activate', '_onParentIronActivate');
},
dettached: function() {
this.unlisten(this.__parent, 'iron-activate', '_onParentIronActivate');
},
/**
* Expand the submenu content.
*/
open: function() {
if (this.disabled)
return;
this.$.collapse.show();
this._active = true;
this.__trigger.classList.add('iron-selected');
},
/**
* Collapse the submenu content.
*/
close: function() {
this.$.collapse.hide();
this._active = false;
this.__trigger.classList.remove('iron-selected');
},
/**
* A handler that is called when the trigger is tapped.
*/
_onTap: function() {
if (this.disabled)
return;
this.$.collapse.toggle();
},
/**
* Toggles the submenu content when the trigger is tapped.
*/
_openedChanged: function(opened, oldOpened) {
if (opened) {
this.fire('paper-submenu-open');
} else if (oldOpened != null) {
this.fire('paper-submenu-close');
}
},
/**
* A handler that is called when `iron-activate` is fired.
*
* @param {CustomEvent} event An `iron-activate` event.
*/
_onParentIronActivate: function(event) {
if (Polymer.Gestures.findOriginalTarget(event) !== this.__parent) {
return;
}
// The activated item can either be this submenu, in which case it
// should be expanded, or any of the other sibling submenus, in which
// case this submenu should be collapsed.
if (event.detail.item == this) {
if (this._active)
return;
this.open();
} else {
this.close();
}
},
/**
* If the dropdown is open when disabled becomes true, close the
* dropdown.
*
* @param {boolean} disabled True if disabled, otherwise false.
*/
_disabledChanged: function(disabled) {
Polymer.IronControlState._disabledChanged.apply(this, arguments);
if (disabled && this._active) {
this.close();
}
}
});
})();
</script>