Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions iron-menu-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
* menu (if there is a relevant item, and it is possible to focus it).
*
* @param {KeyboardEvent} event A KeyboardEvent.
* @return {boolean} Whether an item was focused.
*/
_focusWithKeyboardEvent: function(event) {
this.cancelDebouncer('_clearSearchText');
Expand All @@ -134,6 +135,7 @@
searchText += key.toLocaleLowerCase();

var searchLength = searchText.length;
var itemWasFocused = false;

for (var i = 0, item; item = this.items[i]; i++) {
if (item.hasAttribute('disabled')) {
Expand All @@ -149,13 +151,15 @@

if (title.slice(0, searchLength).toLocaleLowerCase() == searchText) {
this._setFocusedItem(item);
itemWasFocused = true;
break;
}
}

this._searchText = searchText;
this.debounce('_clearSearchText', this._clearSearchText,
this._SEARCH_RESET_TIMEOUT_MS);
return itemWasFocused;
},

_clearSearchText: function() {
Expand Down Expand Up @@ -352,9 +356,12 @@
_onKeydown: function(event) {
if (!this.keyboardEventMatchesKeys(event, 'up down esc')) {
// all other keys focus the menu item starting with that character
this._focusWithKeyboardEvent(event);
if (this._focusWithKeyboardEvent(event)) {
event.stopPropagation();
}
} else {
event.stopPropagation();
}
event.stopPropagation();
},

// override _activateHandler
Expand Down
22 changes: 22 additions & 0 deletions test/iron-menu-behavior.html
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,29 @@
done();
});
});
});

test('keypress which does not focus item does not stop event propagation', function(done) {
var menu = fixture('multi');
MockInteractions.focus(menu);

var onKeyDown = false;
menu.parentElement.addEventListener("keydown", function(event) {
onKeyDown = true;
});

// Wait for async focus
Polymer.Base.async(function() {
// Key press 'u'
MockInteractions.keyDownOn(menu, 85);

Polymer.Base.async(function() {
var focusedItem = Polymer.dom(menu).node.focusedItem;
assert.equal(focusedItem, menu.items[0], 'menu.items[0] is still focused');
assert.equal(onKeyDown, true);
done();
});
});
});

test('focusing non-item content does not auto-focus an item', function(done) {
Expand Down