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 }, | 22 }, |
23 | 23 |
24 listeners: { | 24 listeners: { |
25 'tap': 'showSearch_', | 25 'tap': 'showSearch_', |
26 }, | 26 }, |
27 | 27 |
| 28 /** |
| 29 * @param {boolean} narrow |
| 30 * @return {number} |
| 31 * @private |
| 32 */ |
| 33 computeIconTabIndex_: function(narrow) { |
| 34 return narrow ? 0 : -1; |
| 35 }, |
| 36 |
28 /** @private */ | 37 /** @private */ |
29 onInputBlur_: function() { | 38 onInputBlur_: function() { |
30 if (!this.hasSearchText) | 39 if (!this.hasSearchText) |
31 this.showingSearch = false; | 40 this.showingSearch = false; |
32 }, | 41 }, |
33 | 42 |
34 /** | 43 /** |
| 44 * 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 |
| 46 * 'keydown' to avoid expanding on non-text keys (shift, escape, etc). |
| 47 * @private |
| 48 */ |
| 49 onSearchTermKeypress_: function() { |
| 50 this.showingSearch = true; |
| 51 }, |
| 52 |
| 53 /** |
35 * @param {Event} e | 54 * @param {Event} e |
36 * @private | 55 * @private |
37 */ | 56 */ |
38 showSearch_: function(e) { | 57 showSearch_: function(e) { |
39 if (e.target != this.$.clearSearch) | 58 if (e.target != this.$.clearSearch) |
40 this.showingSearch = true; | 59 this.showingSearch = true; |
41 }, | 60 }, |
42 | 61 |
43 /** | 62 /** |
44 * @param {Event} e | 63 * @param {Event} e |
45 * @private | 64 * @private |
46 */ | 65 */ |
47 hideSearch_: function(e) { | 66 hideSearch_: function(e) { |
48 this.showingSearch = false; | 67 this.showingSearch = false; |
49 e.stopPropagation(); | 68 e.stopPropagation(); |
50 } | 69 } |
51 }); | 70 }); |
OLD | NEW |