5 var PaperMenuButton = Polymer({
6 is: 'paper-menu-button',
9 * Fired when the dropdown opens.
11 * @event paper-dropdown-open
15 * Fired when the dropdown closes.
17 * @event paper-dropdown-close
21 Polymer.IronA11yKeysBehavior,
22 Polymer.IronControlState
28 * True if the content is currently displayed.
34 observer: '_openedChanged'
38 * The orientation against which to align the menu dropdown
39 * horizontally relative to the dropdown trigger.
44 reflectToAttribute: true
48 * The orientation against which to align the menu dropdown
49 * vertically relative to the dropdown trigger.
54 reflectToAttribute: true
58 * A pixel value that will be added to the position calculated for the
59 * given `horizontalAlign`. Use a negative value to offset to the
60 * left, or a positive value to offset to the right.
69 * A pixel value that will be added to the position calculated for the
70 * given `verticalAlign`. Use a negative value to offset towards the
71 * top, or a positive value to offset towards the bottom.
80 * Set to true to disable animations when opening and closing the
89 * Set to true to disable automatically closing the dropdown after
90 * a selection has been made.
98 * An animation config. If provided, this will be used to animate the
99 * opening of the dropdown.
101 openAnimationConfig: {
105 name: 'fade-in-animation',
111 name: 'paper-menu-grow-width-animation',
115 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER
118 name: 'paper-menu-grow-height-animation',
122 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER
129 * An animation config. If provided, this will be used to animate the
130 * closing of the dropdown.
132 closeAnimationConfig: {
136 name: 'fade-out-animation',
141 name: 'paper-menu-shrink-width-animation',
145 easing: PaperMenuButton.ANIMATION_CUBIC_BEZIER
148 name: 'paper-menu-shrink-height-animation',
158 * This is the element intended to be bound as the focus target
159 * for the `iron-dropdown` contained by `paper-menu-button`.
168 'aria-haspopup': 'true'
172 'iron-select': '_onIronSelect'
176 * The content element that is contained by the menu button, if any.
178 get contentElement() {
179 return Polymer.dom(this.$.content).getDistributedNodes()[0];
183 * Make the dropdown content appear as an overlay positioned relative
184 * to the dropdown trigger.
191 this.$.dropdown.open();
195 * Hide the dropdown content.
198 this.$.dropdown.close();
202 * When an `iron-select` event is received, the dropdown should
203 * automatically close on the assumption that a value has been chosen.
205 * @param {CustomEvent} event A CustomEvent instance with type
206 * set to `"iron-select"`.
208 _onIronSelect: function(event) {
209 if (!this.ignoreSelect) {
215 * When the dropdown opens, the `paper-menu-button` fires `paper-open`.
216 * When the dropdown closes, the `paper-menu-button` fires `paper-close`.
218 * @param {boolean} opened True if the dropdown is opened, otherwise false.
219 * @param {boolean} oldOpened The previous value of `opened`.
221 _openedChanged: function(opened, oldOpened) {
223 // TODO(cdata): Update this when we can measure changes in distributed
224 // children in an idiomatic way.
225 // We poke this property in case the element has changed. This will
226 // cause the focus target for the `iron-dropdown` to be updated as
228 this._dropdownContent = this.contentElement;
229 this.fire('paper-dropdown-open');
230 } else if (oldOpened != null) {
231 this.fire('paper-dropdown-close');
236 * If the dropdown is open when disabled becomes true, close the
239 * @param {boolean} disabled True if disabled, otherwise false.
241 _disabledChanged: function(disabled) {
242 Polymer.IronControlState._disabledChanged.apply(this, arguments);
243 if (disabled && this.opened) {
249 PaperMenuButton.ANIMATION_CUBIC_BEZIER = 'cubic-bezier(.3,.95,.5,1)';
250 PaperMenuButton.MAX_ANIMATION_TIME_MS = 400;
252 Polymer.PaperMenuButton = PaperMenuButton;