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

Side by Side Diff: ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.js

Issue 2586803002: MD Settings: Fix label visibility in subpage search fields (Closed)
Patch Set: Rebase Created 3 years, 11 months 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 unified diff | Download patch
« no previous file with comments | « ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.html ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 Polymer({ 5 Polymer({
6 is: 'cr-toolbar-search-field', 6 is: 'cr-toolbar-search-field',
7 7
8 behaviors: [CrSearchFieldBehavior], 8 behaviors: [CrSearchFieldBehavior],
9 9
10 properties: { 10 properties: {
(...skipping 14 matching lines...) Expand all
25 label: String, 25 label: String,
26 26
27 // Tooltip to display on the clear search button. 27 // Tooltip to display on the clear search button.
28 clearLabel: String, 28 clearLabel: String,
29 29
30 // 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
31 // 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.
32 spinnerActive: {type: Boolean, reflectToAttribute: true}, 32 spinnerActive: {type: Boolean, reflectToAttribute: true},
33 33
34 /** @private */ 34 /** @private */
35 hasSearchText_: {type: Boolean, reflectToAttribute: true},
36
37 /** @private */
38 isSpinnerShown_: { 35 isSpinnerShown_: {
39 type: Boolean, 36 type: Boolean,
40 computed: 'computeIsSpinnerShown_(spinnerActive, showingSearch)' 37 computed: 'computeIsSpinnerShown_(spinnerActive, showingSearch)'
41 }, 38 },
42 39
43 /** @private */ 40 /** @private */
44 searchFocused_: {type: Boolean, value: false}, 41 searchFocused_: {type: Boolean, value: false},
45 }, 42 },
46 43
47 listeners: { 44 listeners: {
48 // Deliberately uses 'click' instead of 'tap' to fix crbug.com/624356. 45 // Deliberately uses 'click' instead of 'tap' to fix crbug.com/624356.
49 'click': 'showSearch_', 46 'click': 'showSearch_',
50 }, 47 },
51 48
52 /** @return {!HTMLInputElement} */ 49 /** @return {!HTMLInputElement} */
53 getSearchInput: function() { 50 getSearchInput: function() {
54 return this.$.searchInput; 51 return this.$.searchInput;
55 }, 52 },
56 53
57 /**
58 * Sets the value of the search field. Overridden from CrSearchFieldBehavior.
59 * @param {string} value
60 * @param {boolean=} opt_noEvent Whether to prevent a 'search-changed' event
61 * firing for this change.
62 */
63 setValue: function(value, opt_noEvent) {
64 CrSearchFieldBehavior.setValue.call(this, value, opt_noEvent);
65 this.onSearchInput_();
66 },
67
68 /** @return {boolean} */ 54 /** @return {boolean} */
69 isSearchFocused: function() { 55 isSearchFocused: function() {
70 return this.searchFocused_; 56 return this.searchFocused_;
71 }, 57 },
72 58
73 showAndFocus: function() { 59 showAndFocus: function() {
74 this.showingSearch = true; 60 this.showingSearch = true;
75 this.focus_(); 61 this.focus_();
76 }, 62 },
77 63
64 onSearchTermInput: function() {
65 CrSearchFieldBehavior.onSearchTermInput.call(this);
66 this.showingSearch = this.hasSearchText || this.isSearchFocused();
67 },
68
78 /** @private */ 69 /** @private */
79 focus_: function() { 70 focus_: function() {
80 this.getSearchInput().focus(); 71 this.getSearchInput().focus();
81 }, 72 },
82 73
83 /** 74 /**
84 * @param {boolean} narrow 75 * @param {boolean} narrow
85 * @return {number} 76 * @return {number}
86 * @private 77 * @private
87 */ 78 */
(...skipping 10 matching lines...) Expand all
98 }, 89 },
99 90
100 /** @private */ 91 /** @private */
101 onInputFocus_: function() { 92 onInputFocus_: function() {
102 this.searchFocused_ = true; 93 this.searchFocused_ = true;
103 }, 94 },
104 95
105 /** @private */ 96 /** @private */
106 onInputBlur_: function() { 97 onInputBlur_: function() {
107 this.searchFocused_ = false; 98 this.searchFocused_ = false;
108 if (!this.hasSearchText_) 99 if (!this.hasSearchText)
109 this.showingSearch = false; 100 this.showingSearch = false;
110 }, 101 },
111 102
112 /**
113 * Update the state of the search field whenever the underlying input value
114 * changes. Unlike onsearch or onkeypress, this is reliably called immediately
115 * after any change, whether the result of user input or JS modification.
116 * @private
117 */
118 onSearchInput_: function() {
119 var newValue = this.$.searchInput.value;
120 this.hasSearchText_ = newValue != '';
121 if (newValue != '')
122 this.showingSearch = true;
123 },
124
125 /** @private */ 103 /** @private */
126 onSearchTermKeydown_: function(e) { 104 onSearchTermKeydown_: function(e) {
127 if (e.key == 'Escape') 105 if (e.key == 'Escape')
128 this.showingSearch = false; 106 this.showingSearch = false;
129 }, 107 },
130 108
131 /** 109 /**
132 * @param {Event} e 110 * @param {Event} e
133 * @private 111 * @private
134 */ 112 */
(...skipping 23 matching lines...) Expand all
158 136
159 if (this.showingSearch) { 137 if (this.showingSearch) {
160 this.focus_(); 138 this.focus_();
161 return; 139 return;
162 } 140 }
163 141
164 this.setValue(''); 142 this.setValue('');
165 this.getSearchInput().blur(); 143 this.getSearchInput().blur();
166 }, 144 },
167 }); 145 });
OLDNEW
« no previous file with comments | « ui/webui/resources/cr_elements/cr_toolbar/cr_toolbar_search_field.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698