on xenial help sign in
Clicking on an open menu closes it + test
85c1120Albert Astals Cid
qml/ApplicationMenus/MenuBar.qml+7−1
@@ -199,7 +199,13 @@ Item {
199 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
199 updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
200 }
200 }
201 }
201 }
202+ onClicked: {
203+ var prevItem = d.currentItem;
202− onClicked: updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
204+ updateCurrentItemFromPosition(Qt.point(mouse.x, mouse.y))
205+ if (prevItem && d.currentItem == prevItem) {
206+ prevItem.hide();
207+ }
208+ }
203
209
204 function updateCurrentItemFromPosition(point) {
210 function updateCurrentItemFromPosition(point) {
205 var pos = mapToItem(row, point.x, point.y);
211 var pos = mapToItem(row, point.x, point.y);
tests/qmltests/ApplicationMenus/tst_MenuBar.qml+16
@@ -214,5 +214,21 @@ Item {
214
214
215 compare(priv.currentItem, null, "CurrentItem should be null");
215 compare(priv.currentItem, null, "CurrentItem should be null");
216 }
216 }
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+ }
217 }
233 }
218}
234}