on xenial help sign in
Merge lp:~aacid/unity8/search_suggestion_disappear_typing
67d8256Albert Astals
qml/Components/PageHeader.qml+15−7
@@ -52,6 +52,12 @@ Item {
52 }
52 }
53 }
53 }
54
54
55+ function closePopup() {
56+ if (headerContainer.popover != null) {
57+ PopupUtils.close(headerContainer.popover);
58+ }
59+ }
60+
55 function resetSearch(keepFocus) {
61 function resetSearch(keepFocus) {
56 if (searchHistory) {
62 if (searchHistory) {
57 searchHistory.addQuery(searchTextField.text);
63 searchHistory.addQuery(searchTextField.text);
@@ -60,9 +66,7 @@ Item {
60 unfocus();
66 unfocus();
61 }
67 }
62 searchTextField.text = "";
68 searchTextField.text = "";
63− if (headerContainer.popover != null) {
69+ closePopup();
64− PopupUtils.close(headerContainer.popover);
65− }
66 }
70 }
67
71
68 function unfocus() {
72 function unfocus() {
@@ -103,9 +107,7 @@ Item {
103 anchors { fill: parent; margins: units.gu(1); bottomMargin: units.gu(3) + bottomContainer.height }
107 anchors { fill: parent; margins: units.gu(1); bottomMargin: units.gu(3) + bottomContainer.height }
104 visible: headerContainer.showSearch
108 visible: headerContainer.showSearch
105 onPressed: {
109 onPressed: {
106− if (headerContainer.popover) {
110+ closePopup();
107− PopupUtils.close(headerContainer.popover);
108− }
109 if (!searchTextField.text) {
111 if (!searchTextField.text) {
110 headerContainer.showSearch = false;
112 headerContainer.showSearch = false;
111 }
113 }
@@ -215,6 +217,12 @@ Item {
215 root.openSearchHistory();
217 root.openSearchHistory();
216 }
218 }
217 }
219 }
220+
221+ onTextChanged: {
222+ if (text != "") {
223+ closePopup();
224+ }
225+ }
218 }
226 }
219 }
227 }
220
228
@@ -299,7 +307,7 @@ Item {
299 onClicked: {
307 onClicked: {
300 searchHistory.addQuery(text);
308 searchHistory.addQuery(text);
301 searchTextField.text = text;
309 searchTextField.text = text;
302− PopupUtils.close(popover);
310+ closePopup();
303 unfocus();
311 unfocus();
304 }
312 }
305 }
313 }
tests/qmltests/Components/tst_PageHeader.qml+17−6
@@ -36,6 +36,16 @@ Item {
36
36
37 function init() {
37 function init() {
38 searchEnabled = true;
38 searchEnabled = true;
39+
40+ // Reset to initial state
41+ pageHeader.searchQuery = "";
42+ pageHeader.closePopup();
43+ pageHeader.searchHistory.clear();
44+
45+ // Check initial state
46+ var headerContainer = findChild(pageHeader, "headerContainer");
47+ tryCompareFunction(function() { return headerContainer.popover === null; }, true);
48+ compare(pageHeader.searchHistory.count, 0);
39 }
49 }
40
50
41 function test_search_disabled() {
51 function test_search_disabled() {
@@ -80,9 +90,6 @@ Item {
80 }
90 }
81
91
82 function test_history() {
92 function test_history() {
83− pageHeader.searchHistory.clear()
84− compare(pageHeader.searchHistory.count, 0)
85−
86 pageHeader.triggerSearch()
93 pageHeader.triggerSearch()
87 typeString("humppa1")
94 typeString("humppa1")
88 pageHeader.resetSearch()
95 pageHeader.resetSearch()
@@ -168,14 +175,14 @@ Item {
168 tryCompare(headerContainer.popover, "visible", true);
175 tryCompare(headerContainer.popover, "visible", true);
169 }
176 }
170
177
171− function test_tap_outside_closes_popup_data() {
178+ function test_popup_closing_data() {
172 return [
179 return [
173 { tag: "with search text", searchText: "foobar", hideSearch: false },
180 { tag: "with search text", searchText: "foobar", hideSearch: false },
174 { tag: "without search text", searchText: "", hideSearch: true }
181 { tag: "without search text", searchText: "", hideSearch: true }
175 ];
182 ];
176 }
183 }
177
184
178− function test_tap_outside_closes_popup(data) {
185+ function test_popup_closing(data) {
179 searchEnabled = true;
186 searchEnabled = true;
180 pageHeader.searchHistory.clear();
187 pageHeader.searchHistory.clear();
181
188
@@ -191,7 +198,11 @@ Item {
191
198
192 pageHeader.searchQuery = data.searchText;
199 pageHeader.searchQuery = data.searchText;
193
200
201+ if (data.searchText == "") {
202+ // When the text is empty the user can also close the
203+ // popup by clicking outside the header instead of by starting a search
194− mouseClick(root, root.width / 2, root.height - 1);
204+ mouseClick(root, root.width / 2, root.height - 1);
205+ }
195
206
196 tryCompare(headerContainer, "showSearch", !data.hideSearch);
207 tryCompare(headerContainer, "showSearch", !data.hideSearch);
197 tryCompareFunction(function() { return headerContainer.popover === null; }, true);
208 tryCompareFunction(function() { return headerContainer.popover === null; }, true);