Commit 8658da38 authored by Roman Arora's avatar Roman Arora Committed by Josip Sokcevic

Tab Search: Check for key modifiers before navigation

Check for key event modifires before triggering keyboard navigation.

Fixed: 1111003
Change-Id: Icccfc2938d4812974b628273edc7d68fc825a559
Reviewed-on: https://chrome-internal-review.googlesource.com/c/chrome/browser/resources/tab_search/+/3202978Reviewed-by: default avatarDemetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: default avatarTom Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819580}
parent 492cfe67
...@@ -145,26 +145,39 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -145,26 +145,39 @@ export class TabSearchAppElement extends PolymerElement {
} }
/** /**
* TODO(crbug.com/1111003): Check for the presence of modifiers before
* triggering a navigation.
* @param {!KeyboardEvent} e * @param {!KeyboardEvent} e
* @private * @private
*/ */
onKeyDown_(e) { onKeyDown_(e) {
if (this.selectedIndex_ !== -1) { // Do not interfere with the search field's management of text selection.
if (e.shiftKey) {
return;
}
e.stopPropagation();
if (this.selectedIndex_ === -1) {
// No tabs matching the search text criteria.
return;
}
switch (e.key) { switch (e.key) {
case 'ArrowUp': case 'ArrowUp':
this.selectItem_(-1); this.selectItem_(-1);
e.preventDefault();
break; break;
case 'ArrowDown': case 'ArrowDown':
this.selectItem_(1); this.selectItem_(1);
e.preventDefault();
break; break;
case 'Home': case 'Home':
this.selectItem_(-this.selectedIndex_); this.selectItem_(-this.selectedIndex_);
e.preventDefault();
break; break;
case 'End': case 'End':
this.selectItem_( this.selectItem_(
this.filteredOpenTabs_.length - 1 - this.selectedIndex_); this.filteredOpenTabs_.length - 1 - this.selectedIndex_);
e.preventDefault();
break; break;
case 'Enter': case 'Enter':
const selectedItem = this.filteredOpenTabs_[this.selectedIndex_]; const selectedItem = this.filteredOpenTabs_[this.selectedIndex_];
...@@ -173,9 +186,6 @@ export class TabSearchAppElement extends PolymerElement { ...@@ -173,9 +186,6 @@ export class TabSearchAppElement extends PolymerElement {
} }
} }
e.stopPropagation();
}
/** /**
* @param {number} offset Distance from the desired item to select and the * @param {number} offset Distance from the desired item to select and the
* currently selected item. * currently selected item.
......
...@@ -177,6 +177,18 @@ suite('TabSearchAppTest', () => { ...@@ -177,6 +177,18 @@ suite('TabSearchAppTest', () => {
assertEquals(0, tabSearchApp.getSelectedIndex()); assertEquals(0, tabSearchApp.getSelectedIndex());
}); });
test('Key with modifiers should not affect selected item', async () => {
await setupTest(sampleData());
const searchField = /** @type {!TabSearchSearchField} */
(tabSearchApp.shadowRoot.querySelector('#searchField'));
for (const key of ['ArrowUp', 'ArrowDown', 'Home', 'End']) {
keyDownOn(searchField, 0, ['shift'], key);
assertEquals(0, tabSearchApp.getSelectedIndex());
}
});
test('refresh on tabs changed', async () => { test('refresh on tabs changed', async () => {
await setupTest(sampleData()); await setupTest(sampleData());
verifyTabIds(queryRows(), [1, 5, 6, 2, 3, 4]); verifyTabIds(queryRows(), [1, 5, 6, 2, 3, 4]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment