| 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();
|
| + },
|
| });
|
|
|