| 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. | 5 // TODO(tsergeant): Add tests for cr-toolbar-search-field. |
| 6 Polymer({ | 6 Polymer({ |
| 7 is: 'cr-toolbar-search-field', | 7 is: 'cr-toolbar-search-field', |
| 8 | 8 |
| 9 behaviors: [CrSearchFieldBehavior], | 9 behaviors: [CrSearchFieldBehavior], |
| 10 | 10 |
| 11 properties: { | 11 properties: { |
| 12 narrow: { | 12 narrow: { |
| 13 type: Boolean, | 13 type: Boolean, |
| 14 reflectToAttribute: true, | 14 reflectToAttribute: true, |
| 15 }, | 15 }, |
| 16 | 16 |
| 17 // Prompt text to display in the search field. | 17 // Prompt text to display in the search field. |
| 18 label: String, | 18 label: String, |
| 19 | 19 |
| 20 // Tooltip to display on the clear search button. | 20 // Tooltip to display on the clear search button. |
| 21 clearLabel: String, | 21 clearLabel: String, |
| 22 |
| 23 // 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. |
| 25 spinnerActive: { |
| 26 type: Boolean, |
| 27 reflectToAttribute: true |
| 28 }, |
| 22 }, | 29 }, |
| 23 | 30 |
| 24 listeners: { | 31 listeners: { |
| 25 'tap': 'showSearch_', | 32 'tap': 'showSearch_', |
| 26 }, | 33 }, |
| 27 | 34 |
| 28 /** | 35 /** |
| 29 * @param {boolean} narrow | 36 * @param {boolean} narrow |
| 30 * @return {number} | 37 * @return {number} |
| 31 * @private | 38 * @private |
| 32 */ | 39 */ |
| 33 computeIconTabIndex_: function(narrow) { | 40 computeIconTabIndex_: function(narrow) { |
| 34 return narrow ? 0 : -1; | 41 return narrow ? 0 : -1; |
| 35 }, | 42 }, |
| 36 | 43 |
| 44 /** |
| 45 * @param {boolean} spinnerActive |
| 46 * @param {boolean} showingSearch |
| 47 * @return {boolean} |
| 48 * @private |
| 49 */ |
| 50 isSpinnerShown_: function(spinnerActive, showingSearch) { |
| 51 return spinnerActive && showingSearch; |
| 52 }, |
| 53 |
| 37 /** @private */ | 54 /** @private */ |
| 38 onInputBlur_: function() { | 55 onInputBlur_: function() { |
| 39 if (!this.hasSearchText) | 56 if (!this.hasSearchText) |
| 40 this.showingSearch = false; | 57 this.showingSearch = false; |
| 41 }, | 58 }, |
| 42 | 59 |
| 43 /** | 60 /** |
| 44 * Expand the search field when a key is pressed with it focused. This ensures | 61 * Expand the search field when a key is pressed with it focused. This ensures |
| 45 * it can be used correctly by tab-focusing. 'keypress' is used instead of | 62 * it can be used correctly by tab-focusing. 'keypress' is used instead of |
| 46 * 'keydown' to avoid expanding on non-text keys (shift, escape, etc). | 63 * 'keydown' to avoid expanding on non-text keys (shift, escape, etc). |
| (...skipping 14 matching lines...) Expand all Loading... |
| 61 | 78 |
| 62 /** | 79 /** |
| 63 * @param {Event} e | 80 * @param {Event} e |
| 64 * @private | 81 * @private |
| 65 */ | 82 */ |
| 66 hideSearch_: function(e) { | 83 hideSearch_: function(e) { |
| 67 this.showingSearch = false; | 84 this.showingSearch = false; |
| 68 e.stopPropagation(); | 85 e.stopPropagation(); |
| 69 } | 86 } |
| 70 }); | 87 }); |
| OLD | NEW |