Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(268)

Unified Diff: ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.js

Issue 2571583004: MD WebUI: Delete cr-search-field, simplify CrSearchFieldBehavior (Closed)
Patch Set: Use focus_() Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.js
diff --git a/ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.js b/ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.js
index 51603defca0243af2c0bdc3ce25ad7bbb9c6f152..19318681bd1ca60756f2b60bc6a472965a3f9d4d 100644
--- a/ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.js
+++ b/ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.js
@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// TODO(tsergeant): Add tests for cr-toolbar-search-field.
Polymer({
is: 'cr-toolbar-search-field',
@@ -14,6 +13,14 @@ Polymer({
reflectToAttribute: true,
},
+ showingSearch: {
+ type: Boolean,
+ value: false,
+ notify: true,
+ observer: 'showingSearchChanged_',
+ reflectToAttribute: true
+ },
+
// Prompt text to display in the search field.
label: String,
@@ -72,6 +79,16 @@ Polymer({
return this.searchFocused_;
},
+ showAndFocus: function() {
+ this.showingSearch = true;
+ this.focus_();
+ },
+
+ /** @private */
+ focus_: function() {
+ this.getSearchInput().focus();
+ },
+
/**
* @param {boolean} narrow
* @return {number}
@@ -114,6 +131,12 @@ Polymer({
this.showingSearch = true;
},
+ /** @private */
+ onSearchTermKeydown_: function(e) {
+ if (e.key == 'Escape')
+ this.showingSearch = false;
+ },
+
/**
* @param {Event} e
* @private
@@ -129,6 +152,25 @@ Polymer({
*/
clearSearch_: function(e) {
this.setValue('');
- this.getSearchInput().focus();
- }
+ this.focus_();
+ },
+
+ /**
+ * @param {boolean} current
+ * @param {boolean|undefined} previous
+ * @private
+ */
+ showingSearchChanged_: function(current, previous) {
+ // Prevent unnecessary 'search-changed' event from firing on startup.
+ if (previous == undefined)
+ return;
+
+ if (this.showingSearch) {
+ this.focus_();
+ return;
+ }
+
+ this.setValue('');
+ this.getSearchInput().blur();
+ },
});
« no previous file with comments | « ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.html ('k') | ui/webui/resources/cr_elements_resources.grdp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698