Commit 830328b1 authored by Dan Beam's avatar Dan Beam Committed by Commit Bot

Local NTP: make Enter on (X) remove suggestion button via keyboard work

FWIW: I tried using capturing (true as third arg to addEventListener)
and stopPropagation()/e.defaultPrevented. Because keypress seems to
be handled before click, it didn't make a difference. So I landed at
target filtering. This has the benefit of never navigating for
elements we don't add to this list, but with the detriment of needing
to explicitly add any new UI elements.

R=mahmadi@chromium.org

Fixed: 1012996
Change-Id: Ie36a90210eee8238d05d026bf370a8bc95160a2c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1851228Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Moe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Dan Beam <dbeam@chromium.org>
Auto-Submit: Dan Beam <dbeam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#704477}
parent 4997f6f2
......@@ -1241,7 +1241,7 @@ function onRealboxKeyDown(e) {
}
if (key === 'Enter') {
if (matchEls[selected]) {
if (matchEls[selected] && matchEls.concat(realboxEl).includes(e.target)) {
// Note: dispatching a MouseEvent here instead of using e.g. .click() as
// this forwards key modifiers. This enables Shift+Enter to open a match
// in a new window, for example.
......
......@@ -581,7 +581,21 @@ test.realbox.testRemoveIcon = function() {
const matchesEl = $(test.realbox.IDS.REALBOX_MATCHES);
assertTrue(matchesEl.classList.contains(test.realbox.CLASSES.REMOVABLE));
matchesEl.querySelector(`.${test.realbox.CLASSES.REMOVE_ICON}`).click();
const enter = new KeyboardEvent('keydown', {
bubbles: true,
cancelable: true,
key: 'Enter',
});
let clicked = false;
matchesEl.children[0].onclick = () => clicked = true;
const icon = matchesEl.querySelector(`.${test.realbox.CLASSES.REMOVE_ICON}`);
icon.dispatchEvent(enter);
assertFalse(clicked);
icon.click();
assertEquals(1, test.realbox.deletedLines.length);
assertEquals(0, test.realbox.deletedLines[0]);
......
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