on xenial help sign in
Merge lp:~aacid/unity8/unfocusSearchEntryOnHistoryPick
commit9e848c131f6310a2cd9dcb8332fb54a0ff6fadd5 authorAlbert Astals <albert.astals@canonical.com> dateMon 28 Jul 2014, 10:56 (12 years ago) parent9a58b2344313cc
2 files changed+44−13
qml/Components/PageHeader.qml+17−7 tests/qmltests/Components/tst_PageHeader.qml+27−6
qml/Components/PageHeader.qml+17−7
@@ -56,6 +56,12 @@ Item {
5656 }
5757 }
5858
59+ function closePopup() {
60+ if (headerContainer.popover != null) {
61+ PopupUtils.close(headerContainer.popover);
62+ }
63+ }
64+
5965 function resetSearch(keepFocus) {
6066 if (searchHistory) {
6167 searchHistory.addQuery(searchTextField.text);
@@ -64,9 +70,7 @@ Item {
6470 unfocus();
6571 }
6672 searchTextField.text = "";
67− if (headerContainer.popover != null) {
68− PopupUtils.close(headerContainer.popover);
69− }
73+ closePopup();
7074 }
7175
7276 function unfocus() {
@@ -107,9 +111,7 @@ Item {
107111 anchors { fill: parent; margins: units.gu(1); bottomMargin: units.gu(3) + bottomContainer.height }
108112 visible: headerContainer.showSearch
109113 onPressed: {
110− if (headerContainer.popover) {
111− PopupUtils.close(headerContainer.popover);
112− }
114+ closePopup();
113115 if (!searchTextField.text) {
114116 headerContainer.showSearch = false;
115117 }
@@ -224,6 +226,12 @@ Item {
224226 root.openSearchHistory();
225227 }
226228 }
229+
230+ onTextChanged: {
231+ if (text != "") {
232+ closePopup();
233+ }
234+ }
227235 }
228236 }
229237
@@ -300,6 +308,7 @@ Item {
300308
301309 Repeater {
302310 id: recentSearches
311+ objectName: "recentSearches"
303312 model: searchHistory
304313
305314 delegate: Standard {
@@ -308,7 +317,8 @@ Item {
308317 onClicked: {
309318 searchHistory.addQuery(text);
310319 searchTextField.text = text;
311− PopupUtils.close(popover);
320+ closePopup();
321+ unfocus();
312322 }
313323 }
314324 }
tests/qmltests/Components/tst_PageHeader.qml+27−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()
@@ -166,16 +173,26 @@ Item {
166173 tryCompareFunction(function() { return headerContainer.popover !== null; }, true);
167174
168175 tryCompare(headerContainer.popover, "visible", true);
176+
177+ var searchTextField = findChild(pageHeader, "searchTextField");
178+ compare(searchTextField.focus, true);
179+
180+ var recentSearches = findChild(headerContainer.popover, "recentSearches");
181+ mouseClick(recentSearches.itemAt(0), 0, 0);
182+
183+ compare(pageHeader.searchQuery, "Search2");
184+ tryCompareFunction(function() { return headerContainer.popover === null; }, true);
185+ compare(searchTextField.focus, false);
169186 }
170187
171− function test_tap_outside_closes_popup_data() {
188+ function test_popup_closing_data() {
172189 return [
173190 { tag: "with search text", searchText: "foobar", hideSearch: false },
174191 { tag: "without search text", searchText: "", hideSearch: true }
175192 ];
176193 }
177194
178− function test_tap_outside_closes_popup(data) {
195+ function test_popup_closing(data) {
179196 searchEnabled = true;
180197 pageHeader.searchHistory.clear();
181198
@@ -191,7 +208,11 @@ Item {
191208
192209 pageHeader.searchQuery = data.searchText;
193210
194− mouseClick(root, root.width / 2, root.height - 1);
211+ if (data.searchText == "") {
212+ // When the text is empty the user can also close the
213+ // popup by clicking outside the header instead of by starting a search
214+ mouseClick(root, root.width / 2, root.height - 1);
215+ }
195216
196217 tryCompare(headerContainer, "showSearch", !data.hideSearch);
197218 tryCompareFunction(function() { return headerContainer.popover === null; }, true);