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

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: Different approach 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 if (this.hasSearchText)
dpapad 2017/01/18 02:52:26 Shouldn't we update the boolean either way? this.
tsergeant 2017/01/18 04:14:05 Hmm, almost: we don't want to close the search fie
67 this.showingSearch = true;
68 },
69
78 /** @private */ 70 /** @private */
79 focus_: function() { 71 focus_: function() {
80 this.getSearchInput().focus(); 72 this.getSearchInput().focus();
81 }, 73 },
82 74
83 /** 75 /**
84 * @param {boolean} narrow 76 * @param {boolean} narrow
85 * @return {number} 77 * @return {number}
86 * @private 78 * @private
87 */ 79 */
(...skipping 10 matching lines...) Expand all
98 }, 90 },
99 91
100 /** @private */ 92 /** @private */
101 onInputFocus_: function() { 93 onInputFocus_: function() {
102 this.searchFocused_ = true; 94 this.searchFocused_ = true;
103 }, 95 },
104 96
105 /** @private */ 97 /** @private */
106 onInputBlur_: function() { 98 onInputBlur_: function() {
107 this.searchFocused_ = false; 99 this.searchFocused_ = false;
108 if (!this.hasSearchText_) 100 if (!this.hasSearchText)
109 this.showingSearch = false; 101 this.showingSearch = false;
110 }, 102 },
111 103
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 */ 104 /** @private */
126 onSearchTermKeydown_: function(e) { 105 onSearchTermKeydown_: function(e) {
127 if (e.key == 'Escape') 106 if (e.key == 'Escape')
128 this.showingSearch = false; 107 this.showingSearch = false;
129 }, 108 },
130 109
131 /** 110 /**
132 * @param {Event} e 111 * @param {Event} e
133 * @private 112 * @private
134 */ 113 */
(...skipping 23 matching lines...) Expand all
158 137
159 if (this.showingSearch) { 138 if (this.showingSearch) {
160 this.focus_(); 139 this.focus_();
161 return; 140 return;
162 } 141 }
163 142
164 this.setValue(''); 143 this.setValue('');
165 this.getSearchInput().blur(); 144 this.getSearchInput().blur();
166 }, 145 },
167 }); 146 });
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