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

Unified Diff: ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js

Issue 2004263002: [Do not commit] MD History: Experimentally implement cr-toolbar using cr-search-field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js
diff --git a/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js b/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js
index a507fc34f663939c5889c21c3a7455d533265b6d..a2210a292c1ff8b80c6ed606720f460651b4ff0c 100644
--- a/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js
+++ b/ui/webui/resources/cr_elements/cr_search_field/cr_search_field.js
@@ -14,7 +14,6 @@ SearchFieldDelegate.prototype = {
var SearchField = Polymer({
is: 'cr-search-field',
-
properties: {
label: {
type: String,
@@ -26,16 +25,31 @@ var SearchField = Polymer({
value: '',
},
- showingSearch_: {
+ showingSearch: {
type: Boolean,
value: false,
+ notify: true,
observer: 'showingSearchChanged_',
+ reflectToAttribute: true
},
+
+ /** @private */
+ hasSearchText_: {
+ type: Boolean,
+ }
+ },
+
+ listeners: {
+ 'tap': 'onTap_'
+ },
+
+ onTap_: function(e) {
+ if (e.target != this.$.clearSearch)
+ this.showAndFocus();
},
/**
- * Returns the value of the search field.
- * @return {string}
+ * @return {string} The value of the search field.
*/
getValue: function() {
var searchInput = this.getSearchInput_();
@@ -50,6 +64,7 @@ var SearchField = Polymer({
var searchInput = this.getSearchInput_();
if (searchInput)
searchInput.value = value;
+ this.hasSearchText_ = this.getValue() != '';
},
/** @param {SearchFieldDelegate} delegate */
@@ -57,25 +72,25 @@ var SearchField = Polymer({
this.delegate_ = delegate;
},
- /** @return {Promise<boolean>} */
+ /** @return {!Promise<boolean>} */
showAndFocus: function() {
- this.showingSearch_ = true;
+ this.showingSearch = true;
return this.focus_();
},
/**
- * @return {Promise<boolean>}
+ * @return {!Promise<boolean>}
* @private
*/
focus_: function() {
return new Promise(function(resolve) {
this.async(function() {
- if (this.showingSearch_) {
+ if (this.showingSearch) {
var searchInput = this.getSearchInput_();
if (searchInput)
searchInput.focus();
}
- resolve(this.showingSearch_);
+ resolve(this.showingSearch);
});
}.bind(this));
},
@@ -85,11 +100,12 @@ var SearchField = Polymer({
* @private
*/
getSearchInput_: function() {
- return this.$$('#search-input');
+ return this.$.searchInput;
},
/** @private */
onSearchTermSearch_: function() {
+ this.hasSearchText_ = this.getValue() != '';
if (this.delegate_)
this.delegate_.onSearchTermSearch(this.getValue());
},
@@ -97,12 +113,12 @@ var SearchField = Polymer({
/** @private */
onSearchTermKeydown_: function(e) {
if (e.keyIdentifier == 'U+001B') // Escape.
- this.showingSearch_ = false;
+ this.showingSearch = false;
},
/** @private */
showingSearchChanged_: function() {
- if (this.showingSearch_) {
+ if (this.showingSearch) {
this.focus_();
return;
}
@@ -117,6 +133,6 @@ var SearchField = Polymer({
/** @private */
toggleShowingSearch_: function() {
- this.showingSearch_ = !this.showingSearch_;
- },
+ this.showingSearch = !this.showingSearch;
+ }
});

Powered by Google App Engine
This is Rietveld 408576698