on xenial help sign in
Hide search history popup as soon as you start typing

As discussed with Mike and Saviq

commit78ed3cef61d0a3ca4452bc1110c71139a1e07fa2 authorAlbert Astals <albert.astals@canonical.com> dateThu 24 Jul 2014, 13:43 (12 years ago) parentb6247b4
2 files changed+32−13
qml/Components/PageHeader.qml+15−7 tests/qmltests/Components/tst_PageHeader.qml+17−6
qml/Components/PageHeader.qml+15−7
@@ -52,6 +52,12 @@ Item {
5252 }
5353 }
5454
55+ function closePopup() {
56+ if (headerContainer.popover != null) {
57+ PopupUtils.close(headerContainer.popover);
58+ }
59+ }
60+
5561 function resetSearch(keepFocus) {
5662 if (searchHistory) {
5763 searchHistory.addQuery(searchTextField.text);
@@ -60,9 +66,7 @@ Item {
6066 unfocus();
6167 }
6268 searchTextField.text = "";
63− if (headerContainer.popover != null) {
64− PopupUtils.close(headerContainer.popover);
65− }
69+ closePopup();
6670 }
6771
6872 function unfocus() {
@@ -103,9 +107,7 @@ Item {
103107 anchors { fill: parent; margins: units.gu(1); bottomMargin: units.gu(3) + bottomContainer.height }
104108 visible: headerContainer.showSearch
105109 onPressed: {
106− if (headerContainer.popover) {
107− PopupUtils.close(headerContainer.popover);
108− }
110+ closePopup();
109111 if (!searchTextField.text) {
110112 headerContainer.showSearch = false;
111113 }
@@ -215,6 +217,12 @@ Item {
215217 root.openSearchHistory();
216218 }
217219 }
220+
221+ onTextChanged: {
222+ if (text != "") {
223+ closePopup();
224+ }
225+ }
218226 }
219227 }
220228
@@ -299,7 +307,7 @@ Item {
299307 onClicked: {
300308 searchHistory.addQuery(text);
301309 searchTextField.text = text;
302− PopupUtils.close(popover);
310+ closePopup();
303311 }
304312 }
305313 }
tests/qmltests/Components/tst_PageHeader.qml+17−6
@@ -36,6 +36,16 @@ Item {
3636
3737 function init() {
3838 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);
3949 }
4050
4151 function test_search_disabled() {
@@ -80,9 +90,6 @@ Item {
8090 }
8191
8292 function test_history() {
83− pageHeader.searchHistory.clear()
84− compare(pageHeader.searchHistory.count, 0)
85−
8693 pageHeader.triggerSearch()
8794 typeString("humppa1")
8895 pageHeader.resetSearch()
@@ -168,14 +175,14 @@ Item {
168175 tryCompare(headerContainer.popover, "visible", true);
169176 }
170177
171− function test_tap_outside_closes_popup_data() {
178+ function test_popup_closing_data() {
172179 return [
173180 { tag: "with search text", searchText: "foobar", hideSearch: false },
174181 { tag: "without search text", searchText: "", hideSearch: true }
175182 ];
176183 }
177184
178− function test_tap_outside_closes_popup(data) {
185+ function test_popup_closing(data) {
179186 searchEnabled = true;
180187 pageHeader.searchHistory.clear();
181188
@@ -191,7 +198,11 @@ Item {
191198
192199 pageHeader.searchQuery = data.searchText;
193200
194− mouseClick(root, root.width / 2, root.height - 1);
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
204+ mouseClick(root, root.width / 2, root.height - 1);
205+ }
195206
196207 tryCompare(headerContainer, "showSearch", !data.hideSearch);
197208 tryCompareFunction(function() { return headerContainer.popover === null; }, true);