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

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

Issue 2090513002: MD Search Field: Properly respond to external changes to search value. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
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 // 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 22
23 // When true, show a loading spinner to indicate that the backend is 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. 24 // processing the search. Will only show if the search field is open.
25 spinnerActive: { 25 spinnerActive: {
26 type: Boolean, 26 type: Boolean,
27 reflectToAttribute: true 27 reflectToAttribute: true
28 }, 28 },
29
30 /** @private */
31 hasSearchText_: Boolean,
29 }, 32 },
30 33
31 listeners: { 34 listeners: {
32 'tap': 'showSearch_', 35 'tap': 'showSearch_',
36 'searchInput.bind-value-changed': 'onBindValueChanged_',
dpapad 2016/06/22 18:18:36 I am a bit confused by the fact that this fix seem
tsergeant 2016/06/23 00:02:49 I made the changes here since the problems I'm try
dpapad 2016/06/23 00:44:19 Thanks for the explanation. Given that the canonic
33 }, 37 },
34 38
35 /** 39 /**
36 * @param {boolean} narrow 40 * @param {boolean} narrow
37 * @return {number} 41 * @return {number}
38 * @private 42 * @private
39 */ 43 */
40 computeIconTabIndex_: function(narrow) { 44 computeIconTabIndex_: function(narrow) {
41 return narrow ? 0 : -1; 45 return narrow ? 0 : -1;
42 }, 46 },
43 47
44 /** 48 /**
45 * @param {boolean} spinnerActive 49 * @param {boolean} spinnerActive
46 * @param {boolean} showingSearch 50 * @param {boolean} showingSearch
47 * @return {boolean} 51 * @return {boolean}
48 * @private 52 * @private
49 */ 53 */
50 isSpinnerShown_: function(spinnerActive, showingSearch) { 54 isSpinnerShown_: function(spinnerActive, showingSearch) {
51 return spinnerActive && showingSearch; 55 return spinnerActive && showingSearch;
52 }, 56 },
53 57
54 /** @private */ 58 /** @private */
55 onInputBlur_: function() { 59 onInputBlur_: function() {
56 if (!this.hasSearchText) 60 if (!this.hasSearchText_)
57 this.showingSearch = false; 61 this.showingSearch = false;
58 }, 62 },
59 63
60 /** 64 /**
61 * Expand the search field when a key is pressed with it focused. This ensures 65 * Update the state of the search field whenever the underlying input value
62 * it can be used correctly by tab-focusing. 'keypress' is used instead of 66 * changes. Unlike onsearch or onkeypress, this is reliably called immediately
63 * 'keydown' to avoid expanding on non-text keys (shift, escape, etc). 67 * after any change, whether the result of user input or JS modification.
64 * @private 68 * @private
65 */ 69 */
66 onSearchTermKeypress_: function() { 70 onBindValueChanged_: function() {
dpapad 2016/06/22 18:18:36 There is already an onValueChanged_() method respo
tsergeant 2016/06/23 00:02:49 I've tried to allude to this in the comment, but w
dpapad 2016/06/23 00:44:19 I understand now, thanks. It was not clear to me i
67 this.showingSearch = true; 71 var newValue = this.$.searchInput.bindValue;
72 this.hasSearchText_ = newValue != '';
73 if (newValue != '')
74 this.showingSearch = true;
68 }, 75 },
69 76
70 /** 77 /**
71 * @param {Event} e 78 * @param {Event} e
72 * @private 79 * @private
73 */ 80 */
74 showSearch_: function(e) { 81 showSearch_: function(e) {
75 if (e.target != this.$.clearSearch) 82 if (e.target != this.$.clearSearch)
76 this.showingSearch = true; 83 this.showingSearch = true;
77 }, 84 },
78 85
79 /** 86 /**
80 * @param {Event} e 87 * @param {Event} e
81 * @private 88 * @private
82 */ 89 */
83 hideSearch_: function(e) { 90 hideSearch_: function(e) {
84 this.showingSearch = false; 91 this.showingSearch = false;
85 e.stopPropagation(); 92 e.stopPropagation();
86 } 93 }
87 }); 94 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698