Commit 298c086c authored by dpapad's avatar dpapad Committed by Commit Bot

Settings WebUI: Close language dialog on esc, if no search query exists.

Bug: 714021
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: I3c96ce501e1d5ff65b8c27f7d04dab83694acc2e
Reviewed-on: https://chromium-review.googlesource.com/1090000Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567361}
parent 1f078c9b
...@@ -45,7 +45,8 @@ ...@@ -45,7 +45,8 @@
<div slot="title">$i18n{addLanguagesDialogTitle}</div> <div slot="title">$i18n{addLanguagesDialogTitle}</div>
<div slot="body" scrollable> <div slot="body" scrollable>
<settings-subpage-search label="$i18n{searchLanguages}" id="search" <settings-subpage-search label="$i18n{searchLanguages}" id="search"
on-search-changed="onSearchChanged_" autofocus> on-search-changed="onSearchChanged_"
on-keydown="onKeydown_" autofocus>
</settings-subpage-search> </settings-subpage-search>
<iron-list class="ripple-padding" scroll-target="[[$$('[slot=body]')]]" <iron-list class="ripple-padding" scroll-target="[[$$('[slot=body]')]]"
items="[[getLanguages_( items="[[getLanguages_(
......
...@@ -149,4 +149,14 @@ Polymer({ ...@@ -149,4 +149,14 @@ Polymer({
this.languageHelper.enableLanguage(languageCode); this.languageHelper.enableLanguage(languageCode);
}); });
}, },
/**
* @param {!KeyboardEvent} e
* @private
*/
onKeydown_: function(e) {
// Close dialog if 'esc' is pressed and the search box is already empty.
if (e.key == 'Escape' && !this.$.search.getValue().trim())
this.$.dialog.close();
},
}); });
...@@ -213,6 +213,22 @@ cr.define('languages_page_tests', function() { ...@@ -213,6 +213,22 @@ cr.define('languages_page_tests', function() {
Polymer.dom.flush(); Polymer.dom.flush();
assertEquals(0, getItems().length); assertEquals(0, getItems().length);
}); });
test('Escape key behavior', function() {
const searchInput = dialog.$$('settings-subpage-search');
searchInput.setValue('dummyquery');
// Test that dialog is not closed if 'Escape' is pressed on the input
// and a search query exists.
MockInteractions.keyDownOn(searchInput, 19, [], 'Escape');
assertTrue(dialog.$.dialog.open);
// Test that dialog is closed if 'Escape' is pressed on the input and no
// search query exists.
searchInput.setValue('');
MockInteractions.keyDownOn(searchInput, 19, [], 'Escape');
assertFalse(dialog.$.dialog.open);
});
}); });
suite(TestNames.LanguageMenu, function() { suite(TestNames.LanguageMenu, function() {
......
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