Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // TODO(tsergeant): Add tests for cr-toolbar-search-field. | |
| 6 Polymer({ | 5 Polymer({ |
| 7 is: 'cr-toolbar-search-field', | 6 is: 'cr-toolbar-search-field', |
| 8 | 7 |
| 9 behaviors: [CrSearchFieldBehavior], | 8 behaviors: [CrSearchFieldBehavior], |
|
dpapad
2016/12/13 20:02:58
After this CL, I don't think there is any other us
tsergeant
2016/12/14 00:05:55
<settings-subpage-search> uses it in a pretty basi
dpapad
2016/12/14 03:07:07
I see. I guess we can evaluate this separately aft
| |
| 10 | 9 |
| 11 properties: { | 10 properties: { |
| 12 narrow: { | 11 narrow: { |
| 13 type: Boolean, | 12 type: Boolean, |
| 14 reflectToAttribute: true, | 13 reflectToAttribute: true, |
| 15 }, | 14 }, |
| 16 | 15 |
| 16 showingSearch: { | |
| 17 type: Boolean, | |
| 18 value: false, | |
| 19 notify: true, | |
| 20 observer: 'showingSearchChanged_', | |
| 21 reflectToAttribute: true | |
| 22 }, | |
| 23 | |
| 17 // Prompt text to display in the search field. | 24 // Prompt text to display in the search field. |
| 18 label: String, | 25 label: String, |
| 19 | 26 |
| 20 // Tooltip to display on the clear search button. | 27 // Tooltip to display on the clear search button. |
| 21 clearLabel: String, | 28 clearLabel: String, |
| 22 | 29 |
| 23 // When true, show a loading spinner to indicate that the backend is | 30 // When true, show a loading spinner to indicate that the backend is |
| 24 // processing the search. Will only show if the search field is open. | 31 // processing the search. Will only show if the search field is open. |
| 25 spinnerActive: { | 32 spinnerActive: { |
| 26 type: Boolean, | 33 type: Boolean, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 setValue: function(value, opt_noEvent) { | 72 setValue: function(value, opt_noEvent) { |
| 66 CrSearchFieldBehavior.setValue.call(this, value, opt_noEvent); | 73 CrSearchFieldBehavior.setValue.call(this, value, opt_noEvent); |
| 67 this.onSearchInput_(); | 74 this.onSearchInput_(); |
| 68 }, | 75 }, |
| 69 | 76 |
| 70 /** @return {boolean} */ | 77 /** @return {boolean} */ |
| 71 isSearchFocused: function() { | 78 isSearchFocused: function() { |
| 72 return this.searchFocused_; | 79 return this.searchFocused_; |
| 73 }, | 80 }, |
| 74 | 81 |
| 82 showAndFocus: function() { | |
| 83 this.showingSearch = true; | |
| 84 this.focus_(); | |
| 85 }, | |
| 86 | |
| 87 /** @private */ | |
| 88 focus_: function() { | |
| 89 this.getSearchInput().focus(); | |
| 90 }, | |
| 91 | |
| 75 /** | 92 /** |
| 76 * @param {boolean} narrow | 93 * @param {boolean} narrow |
| 77 * @return {number} | 94 * @return {number} |
| 78 * @private | 95 * @private |
| 79 */ | 96 */ |
| 80 computeIconTabIndex_: function(narrow) { | 97 computeIconTabIndex_: function(narrow) { |
| 81 return narrow ? 0 : -1; | 98 return narrow ? 0 : -1; |
| 82 }, | 99 }, |
| 83 | 100 |
| 84 /** | 101 /** |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 107 * after any change, whether the result of user input or JS modification. | 124 * after any change, whether the result of user input or JS modification. |
| 108 * @private | 125 * @private |
| 109 */ | 126 */ |
| 110 onSearchInput_: function() { | 127 onSearchInput_: function() { |
| 111 var newValue = this.$.searchInput.value; | 128 var newValue = this.$.searchInput.value; |
| 112 this.hasSearchText_ = newValue != ''; | 129 this.hasSearchText_ = newValue != ''; |
| 113 if (newValue != '') | 130 if (newValue != '') |
| 114 this.showingSearch = true; | 131 this.showingSearch = true; |
| 115 }, | 132 }, |
| 116 | 133 |
| 134 /** @private */ | |
| 135 onSearchTermKeydown_: function(e) { | |
| 136 if (e.key == 'Escape') | |
| 137 this.showingSearch = false; | |
| 138 }, | |
| 139 | |
| 117 /** | 140 /** |
| 118 * @param {Event} e | 141 * @param {Event} e |
| 119 * @private | 142 * @private |
| 120 */ | 143 */ |
| 121 showSearch_: function(e) { | 144 showSearch_: function(e) { |
| 122 if (e.target != this.$.clearSearch) | 145 if (e.target != this.$.clearSearch) |
| 123 this.showingSearch = true; | 146 this.showingSearch = true; |
| 124 }, | 147 }, |
| 125 | 148 |
| 126 /** | 149 /** |
| 127 * @param {Event} e | 150 * @param {Event} e |
| 128 * @private | 151 * @private |
| 129 */ | 152 */ |
| 130 clearSearch_: function(e) { | 153 clearSearch_: function(e) { |
| 131 this.setValue(''); | 154 this.setValue(''); |
| 132 this.getSearchInput().focus(); | 155 this.getSearchInput().focus(); |
|
dpapad
2016/12/13 20:02:58
Nit: Re-use
this.focus_();
tsergeant
2016/12/14 00:05:55
Done.
| |
| 133 } | 156 }, |
| 157 | |
| 158 /** | |
| 159 * @param {boolean} current | |
| 160 * @param {boolean|undefined} previous | |
| 161 * @private | |
| 162 */ | |
| 163 showingSearchChanged_: function(current, previous) { | |
| 164 // Prevent unnecessary 'search-changed' event from firing on startup. | |
| 165 if (previous == undefined) | |
| 166 return; | |
| 167 | |
| 168 if (this.showingSearch) { | |
| 169 this.focus_(); | |
| 170 return; | |
| 171 } | |
| 172 | |
| 173 this.setValue(''); | |
| 174 this.getSearchInput().blur(); | |
| 175 }, | |
| 134 }); | 176 }); |
| OLD | NEW |