Skip to content

Commit

Permalink
Local NTP: preserve focus when removing suggestions
Browse files Browse the repository at this point in the history
[email protected]

Fixed: 1012997
Change-Id: I6b5c1cf5b740777b521034920fd56455f85e4293
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1851285
Auto-Submit: Dan Beam <[email protected]>
Commit-Queue: Hector Carmona <[email protected]>
Reviewed-by: Hector Carmona <[email protected]>
Cr-Commit-Position: refs/heads/master@{#704871}
danbeam authored and Commit Bot committed Oct 10, 2019
1 parent 1fede15 commit 2b5dbda
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 14 additions & 1 deletion chrome/browser/resources/local_ntp/local_ntp.js
Original file line number Diff line number Diff line change
@@ -1083,15 +1083,28 @@ function onDeleteAutocompleteMatch(result) {
return matchEl.classList.contains(CLASSES.SELECTED);
});

const wasFocused = matchEls[selected].contains(document.activeElement);

populateAutocompleteMatches(result.matches);

if (result.matches.length === 0) {
if (wasFocused) {
$(IDS.REALBOX).focus();
}
return;
}

const newMatchEls = Array.from($(IDS.REALBOX_MATCHES).children);
const newSelected = Math.min(newMatchEls.length - 1, selected);
selectMatchEl(newMatchEls[newSelected]);
const newSelectedEl = newMatchEls[newSelected];

selectMatchEl(newSelectedEl);

if (wasFocused) {
const removeIcon = newSelectedEl.querySelector(`.${CLASSES.REMOVE_ICON}`);
assert(removeIcon || newSelectedEl).focus();
}

updateRealboxOutput({
moveCursorToEnd: true,
inline: '',
7 changes: 6 additions & 1 deletion chrome/test/data/local_ntp/realbox_browsertest.js
Original file line number Diff line number Diff line change
@@ -564,10 +564,15 @@ test.realbox.testSupportedDeletion = function() {
assertEquals(1, test.realbox.deletedLines.length);
assertEquals(1, test.realbox.deletedLines[0]);

matchesEl.children[1].focus();
assertEquals(matchesEl.children[1], document.activeElement);

chrome.embeddedSearch.searchBox.ondeleteautocompletematch(
{success: true, matches: [test.realbox.getSearchMatch()]});

assertEquals(1, $(test.realbox.IDS.REALBOX_MATCHES).children.length);
const newMatchesEl = $(test.realbox.IDS.REALBOX_MATCHES);
assertEquals(1, newMatchesEl.children.length);
assertEquals(newMatchesEl.children[0], document.activeElement);
};

test.realbox.testRemoveIcon = function() {

0 comments on commit 2b5dbda

Please sign in to comment.