Chromium Code Reviews| Index: ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js |
| diff --git a/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js b/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js |
| index e24e30935380f9a1d3e6f04475e3f6b031e046cc..2b39c58a431afbfb7924f5f69c57f28380833e6a 100644 |
| --- a/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js |
| +++ b/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js |
| @@ -29,21 +29,47 @@ var SearchField = Polymer({ |
| showingSearch_: { |
| type: Boolean, |
| value: false, |
| + observer: 'showingSearchChanged_', |
| }, |
| }, |
| + /** |
| + * Returns the value of the search field. |
| + * @return {string} |
| + */ |
| + getValue: function() { |
| + var searchInput = this.getSearchInput_(); |
| + return searchInput ? searchInput.value : ''; |
| + }, |
| + |
| /** @param {SearchFieldDelegate} delegate */ |
| setDelegate: function(delegate) { |
| this.delegate_ = delegate; |
| }, |
| + showAndFocus: function() { |
| + this.showingSearch_ = true; |
| + this.focus_(); |
| + }, |
| + |
| + /** @private */ |
| + focus_: function() { |
| + this.async(function() { |
| + if (!this.showingSearch_) |
| + return; |
| + |
| + var searchInput = this.getSearchInput_(); |
| + if (searchInput) |
| + searchInput.focus(); |
| + }); |
| + }, |
| + |
| /** |
| - * Returns the value of the search field. |
| - * @return {string} |
| + * @return {?HTMLElement} |
| + * @private |
| */ |
| - getValue: function() { |
| - var searchInput = this.$$('#search-input'); |
| - return searchInput ? searchInput.value : ''; |
| + getSearchInput_: function() { |
| + return this.$$('#search-input'); |
| }, |
| /** @private */ |
| @@ -54,22 +80,27 @@ var SearchField = Polymer({ |
| /** @private */ |
| onSearchTermKeydown_: function(e) { |
| - assert(this.showingSearch_); |
| if (e.keyIdentifier == 'U+001B') // Escape. |
| - this.toggleShowingSearch_(); |
| + this.showingSearch_ = false; |
| + }, |
| + |
| + /** @private */ |
| + showingSearchChanged_: function() { |
| + if (this.showingSearch_) { |
| + this.focus_(); |
| + return; |
| + } |
| + |
| + var searchInput = this.getSearchInput_(); |
| + if (!searchInput) |
| + return; |
| + |
| + searchInput.value = ''; |
| + this.onSearchTermSearch_(); |
| }, |
| /** @private */ |
| toggleShowingSearch_: function() { |
|
michaelpg
2016/01/21 23:43:35
unused now?
Dan Beam
2016/01/21 23:54:23
nope, in html
|
| this.showingSearch_ = !this.showingSearch_; |
| - this.async(function() { |
| - var searchInput = this.$$('#search-input'); |
| - if (this.showingSearch_) { |
| - searchInput.focus(); |
| - } else { |
| - searchInput.value = ''; |
| - this.onSearchTermSearch_(); |
| - } |
| - }); |
| }, |
| }); |