| OLD | NEW |
| 1 /** | 1 /** |
| 2 * `Polymer.IronMenuBehavior` implements accessible menu behavior. | 2 * `Polymer.IronMenuBehavior` implements accessible menu behavior. |
| 3 * | 3 * |
| 4 * @demo demo/index.html | 4 * @demo demo/index.html |
| 5 * @polymerBehavior Polymer.IronMenuBehavior | 5 * @polymerBehavior Polymer.IronMenuBehavior |
| 6 */ | 6 */ |
| 7 Polymer.IronMenuBehaviorImpl = { | 7 Polymer.IronMenuBehaviorImpl = { |
| 8 | 8 |
| 9 properties: { | 9 properties: { |
| 10 | 10 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 this._resetTabindices(); | 54 this._resetTabindices(); |
| 55 }, | 55 }, |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * Selects the given value. If the `multi` property is true, then the select
ed state of the | 58 * Selects the given value. If the `multi` property is true, then the select
ed state of the |
| 59 * `value` will be toggled; otherwise the `value` will be selected. | 59 * `value` will be toggled; otherwise the `value` will be selected. |
| 60 * | 60 * |
| 61 * @param {string|number} value the value to select. | 61 * @param {string|number} value the value to select. |
| 62 */ | 62 */ |
| 63 select: function(value) { | 63 select: function(value) { |
| 64 // Cancel automatically focusing a default item if the menu received focus |
| 65 // through a user action selecting a particular item. |
| 64 if (this._defaultFocusAsync) { | 66 if (this._defaultFocusAsync) { |
| 65 this.cancelAsync(this._defaultFocusAsync); | 67 this.cancelAsync(this._defaultFocusAsync); |
| 66 this._defaultFocusAsync = null; | 68 this._defaultFocusAsync = null; |
| 67 } | 69 } |
| 68 var item = this._valueToItem(value); | 70 var item = this._valueToItem(value); |
| 69 if (item && item.hasAttribute('disabled')) return; | 71 if (item && item.hasAttribute('disabled')) return; |
| 70 this._setFocusedItem(item); | 72 this._setFocusedItem(item); |
| 71 Polymer.IronMultiSelectableBehaviorImpl.select.apply(this, arguments); | 73 Polymer.IronMultiSelectableBehaviorImpl.select.apply(this, arguments); |
| 72 }, | 74 }, |
| 73 | 75 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 226 } |
| 225 | 227 |
| 226 // Do not focus the selected tab if the deepest target is part of the | 228 // Do not focus the selected tab if the deepest target is part of the |
| 227 // menu element's local DOM and is focusable. | 229 // menu element's local DOM and is focusable. |
| 228 var rootTarget = /** @type {?HTMLElement} */( | 230 var rootTarget = /** @type {?HTMLElement} */( |
| 229 Polymer.dom(event).rootTarget); | 231 Polymer.dom(event).rootTarget); |
| 230 if (rootTarget !== this && typeof rootTarget.tabIndex !== "undefined" && !
this.isLightDescendant(rootTarget)) { | 232 if (rootTarget !== this && typeof rootTarget.tabIndex !== "undefined" && !
this.isLightDescendant(rootTarget)) { |
| 231 return; | 233 return; |
| 232 } | 234 } |
| 233 | 235 |
| 234 this.blur(); | |
| 235 | |
| 236 // clear the cached focus item | 236 // clear the cached focus item |
| 237 this._defaultFocusAsync = this.async(function() { | 237 this._defaultFocusAsync = this.async(function() { |
| 238 // focus the selected item when the menu receives focus, or the first it
em | 238 // focus the selected item when the menu receives focus, or the first it
em |
| 239 // if no item is selected | 239 // if no item is selected |
| 240 var selectedItem = this.multi ? (this.selectedItems && this.selectedItem
s[0]) : this.selectedItem; | 240 var selectedItem = this.multi ? (this.selectedItems && this.selectedItem
s[0]) : this.selectedItem; |
| 241 | 241 |
| 242 this._setFocusedItem(null); | 242 this._setFocusedItem(null); |
| 243 | 243 |
| 244 if (selectedItem) { | 244 if (selectedItem) { |
| 245 this._setFocusedItem(selectedItem); | 245 this._setFocusedItem(selectedItem); |
| 246 } else { | 246 } else if (this.items[0]) { |
| 247 this._setFocusedItem(this.items[0]); | 247 this._setFocusedItem(this.items[0]); |
| 248 } | 248 } |
| 249 // async 1ms to wait for `select` to get called from `_itemActivate` | 249 }); |
| 250 }, 1); | |
| 251 }, | 250 }, |
| 252 | 251 |
| 253 /** | 252 /** |
| 254 * Handler that is called when the up key is pressed. | 253 * Handler that is called when the up key is pressed. |
| 255 * | 254 * |
| 256 * @param {CustomEvent} event A key combination event. | 255 * @param {CustomEvent} event A key combination event. |
| 257 */ | 256 */ |
| 258 _onUpKey: function(event) { | 257 _onUpKey: function(event) { |
| 259 // up and down arrows moves the focus | 258 // up and down arrows moves the focus |
| 260 this._focusPrevious(); | 259 this._focusPrevious(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 }; | 301 }; |
| 303 | 302 |
| 304 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; | 303 Polymer.IronMenuBehaviorImpl._shiftTabPressed = false; |
| 305 | 304 |
| 306 /** @polymerBehavior Polymer.IronMenuBehavior */ | 305 /** @polymerBehavior Polymer.IronMenuBehavior */ |
| 307 Polymer.IronMenuBehavior = [ | 306 Polymer.IronMenuBehavior = [ |
| 308 Polymer.IronMultiSelectableBehavior, | 307 Polymer.IronMultiSelectableBehavior, |
| 309 Polymer.IronA11yKeysBehavior, | 308 Polymer.IronA11yKeysBehavior, |
| 310 Polymer.IronMenuBehaviorImpl | 309 Polymer.IronMenuBehaviorImpl |
| 311 ]; | 310 ]; |
| OLD | NEW |