| Index: third_party/polymer/v1_0/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js
|
| diff --git a/third_party/polymer/v1_0/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js b/third_party/polymer/v1_0/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js
|
| index bb0ed59e2e21ff20d5f661090b23079d7bca2f0c..85b7836b141f3b8de7d383de645ca48ea72504da 100644
|
| --- a/third_party/polymer/v1_0/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js
|
| +++ b/third_party/polymer/v1_0/components-chromium/iron-menu-behavior/iron-menu-behavior-extracted.js
|
| @@ -25,12 +25,21 @@
|
| */
|
| attrForItemTitle: {
|
| type: String
|
| - }
|
| + },
|
| +
|
| + disabled: {
|
| + type: Boolean,
|
| + value: false,
|
| + observer: '_disabledChanged',
|
| + },
|
| },
|
|
|
| + _SEARCH_RESET_TIMEOUT_MS: 1000,
|
| +
|
| + _previousTabIndex: 0,
|
| +
|
| hostAttributes: {
|
| 'role': 'menu',
|
| - 'tabindex': '0'
|
| },
|
|
|
| observers: [
|
| @@ -108,16 +117,40 @@
|
| * @param {KeyboardEvent} event A KeyboardEvent.
|
| */
|
| _focusWithKeyboardEvent: function(event) {
|
| + this.cancelDebouncer('_clearSearchText');
|
| +
|
| + var searchText = this._searchText || '';
|
| + var key = event.key && event.key.length == 1 ? event.key :
|
| + String.fromCharCode(event.keyCode);
|
| + searchText += key.toLocaleLowerCase();
|
| +
|
| + var searchLength = searchText.length;
|
| +
|
| for (var i = 0, item; item = this.items[i]; i++) {
|
| + if (item.hasAttribute('disabled')) {
|
| + continue;
|
| + }
|
| +
|
| var attr = this.attrForItemTitle || 'textContent';
|
| - var title = item[attr] || item.getAttribute(attr);
|
| + var title = (item[attr] || item.getAttribute(attr) || '').trim();
|
|
|
| - if (!item.hasAttribute('disabled') && title &&
|
| - title.trim().charAt(0).toLowerCase() === String.fromCharCode(event.keyCode).toLowerCase()) {
|
| + if (title.length < searchLength) {
|
| + continue;
|
| + }
|
| +
|
| + if (title.slice(0, searchLength).toLocaleLowerCase() == searchText) {
|
| this._setFocusedItem(item);
|
| break;
|
| }
|
| }
|
| +
|
| + this._searchText = searchText;
|
| + this.debounce('_clearSearchText', this._clearSearchText,
|
| + this._SEARCH_RESET_TIMEOUT_MS);
|
| + },
|
| +
|
| + _clearSearchText: function() {
|
| + this._searchText = '';
|
| },
|
|
|
| /**
|
| @@ -195,7 +228,7 @@
|
| */
|
| _focusedItemChanged: function(focusedItem, old) {
|
| old && old.setAttribute('tabindex', '-1');
|
| - if (focusedItem) {
|
| + if (focusedItem && !focusedItem.hasAttribute('disabled') && !this.disabled) {
|
| focusedItem.setAttribute('tabindex', '0');
|
| focusedItem.focus();
|
| }
|
| @@ -319,6 +352,19 @@
|
| _activateHandler: function(event) {
|
| Polymer.IronSelectableBehavior._activateHandler.call(this, event);
|
| event.stopPropagation();
|
| + },
|
| +
|
| + /**
|
| + * Updates this element's tab index when it's enabled/disabled.
|
| + * @param {boolean} disabled
|
| + */
|
| + _disabledChanged: function(disabled) {
|
| + if (disabled) {
|
| + this._previousTabIndex = this.hasAttribute('tabindex') ? this.tabIndex : 0;
|
| + this.removeAttribute('tabindex'); // No tabindex means not tab-able or select-able.
|
| + } else if (!this.hasAttribute('tabindex')) {
|
| + this.setAttribute('tabindex', this._previousTabIndex);
|
| + }
|
| }
|
| };
|
|
|
|
|