on xenial help sign in
Clicking on an open menu closes it + test
commit85c112044d40d2194b31bf1cffb3148db3ecc1b4 authorAlbert Astals Cid <albert.astals@canonical.com> dateFri 20 Jan 2017, 17:30 (10 years ago) parentd339861
2 files changed+23−1
qml/ApplicationMenus/MenuBar.qml+7−1 tests/qmltests/ApplicationMenus/tst_MenuBar.qml+16
qml/ApplicationMenus/MenuBar.qml+7−1
@@ -199,7 +199,13 @@ Item {
199199 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
200200 }
201201 }
202− onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
202+ onClicked: {
203+ var prevItem = d.currentItem;
204+ updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
205+ if (prevItem && d.currentItem == prevItem) {
206+ prevItem.hide();
207+ }
208+ }
203209
204210 function updateCurrentItemFromPosition(point) {
205211 var pos = mapToItem(row, point.x, point.y);
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+16
@@ -214,5 +214,21 @@ Item {
214214
215215 compare(priv.currentItem, null, "CurrentItem should be null");
216216 }
217+
218+ function test_clickOpenMenuClosesMenu() {
219+
220+ menuBackend.modelData = appMenuData.generateTestData(3,3,0,0,"menu");
221+ var priv = findInvisibleChild(menuBar, "d");
222+
223+ var menuItem = findChild(menuBar, "menuBar-item0");
224+ waitForRendering(menuItem);
225+ mouseClick(menuItem);
226+ compare(priv.currentItem, menuItem, "CurrentItem should be set to item 0");
227+ compare(priv.currentItem.popupVisible, true, "Popup should be visible");
228+
229+ waitForRendering(menuItem);
230+ mouseClick(menuItem);
231+ compare(priv.currentItem, null, "CurrentItem should be null");
232+ }
217233 }
218234}