private final Grid<?> grid;
+ private NativePreviewHandler clickOutsideToCloseHandler = new NativePreviewHandler() {
+
+ @Override
+ public void onPreviewNativeEvent(NativePreviewEvent event) {
+ if (event.getTypeInt() != Event.ONMOUSEDOWN) {
+ return;
+ }
+
+ // Click outside the panel
+ EventTarget clickTarget = event.getNativeEvent()
+ .getEventTarget();
+ if (!rootContainer.getElement().isOrHasChild(
+ Element.as(clickTarget))) {
+ close();
+ }
+ }
+ };
+
+ private HandlerRegistration clickOutsideToCloseHandlerRegistration;
+
private Sidebar(Grid<?> grid) {
this.grid = grid;
addStyleName("opened");
removeStyleName("closed");
rootContainer.add(content);
+ clickOutsideToCloseHandlerRegistration = Event
+ .addNativePreviewHandler(clickOutsideToCloseHandler);
}
openCloseButton.setHeight("");
}
content.removeFromParent();
// adjust open button to header height when closed
setHeightToHeaderCellHeight();
+ if (clickOutsideToCloseHandlerRegistration != null) {
+ clickOutsideToCloseHandlerRegistration.removeHandler();
+ clickOutsideToCloseHandlerRegistration = null;
+ }
}
}
toggleHidableColumnAPI(6);
toggleHidableColumnAPI(0);
- verifyColumnHidingTogglesOrder(0, 1, 3, 6);
-
+ // Selecting from the menu closes the sidebar
clickSidebarOpenButton();
+ verifyColumnHidingTogglesOrder(0, 1, 3, 6);
+
toggleHidableColumnAPI(2);
toggleHidableColumnAPI(4);
toggleHidableColumnAPI(7);
verifyColumnIsNotFrozen(1);
verifyColumnIsNotFrozen(2);
+ getSidebarOpenButton().click();
getColumnHidingToggle(2).click();
verifyColumnIsFrozen(0);
verifyColumnIsFrozen(1);
}
assertEquals(colCount, getGridHeaderRowCells().size());
+ }
+ @Test
+ public void testColumnHidingPopupClosedWhenClickingOutside() {
+ selectMenuPath("Component", "Columns", "Column 0", "Hidable");
+ getSidebarOpenButton().click();
+ verifySidebarOpened();
+ findElement(By.className("v-app")).click();
+ verifySidebarClosed();
}
@Test
}
@Test
- public void testProgrammaticSidebarToggle() {
+ public void testProgrammaticSidebarOpen() {
openTestURL();
selectMenuPath("Component", "Columns", "Column 0", "Hidable");
selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility");
- Assert.assertEquals("Sidebar be open", 1,
- countBySelector(".v-grid-sidebar-content"));
-
- selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility");
-
- Assert.assertEquals("Sidebar be closed", 0,
+ Assert.assertEquals("Sidebar should be open", 1,
countBySelector(".v-grid-sidebar-content"));
}
"Header (0,1)");
selectMenuPath("Component", "Columns", "Column 2", "Hidable");
+ selectMenuPath("Component", "Sidebar", "Toggle sidebar visibility");
// Adding a new togglable column should have restored the expected order
assertSidebarMenuItems("Header (0,0)", "Header (0,1)", "Header (0,2)",
assertEquals("Column 1", getColumnHidingToggle(1).getText());
toggleColumnHidingToggleCaptionChange(1);
+
+ getSidebarOpenButton().click();
assertEquals("column 1", getGridElement().getHeaderCell(0, 1).getText()
.toLowerCase());
assertEquals("Column 1 caption 0", getColumnHidingToggle(1).getText());
toggleColumnHidingToggleCaptionChange(1);
+ getSidebarOpenButton().click();
assertEquals("Column 1 caption 1", getColumnHidingToggle(1).getText());
}
selectMenuPath("Component", "Columns", "Column 1", "Header Type",
"Widget Header");
+ getSidebarOpenButton().click();
assertEquals("Column 1", getColumnHidingToggle(1).getText());
}
verifyColumnNotFrozen(0);
verifyColumnNotFrozen(1);
+ getSidebarOpenButton().click();
getColumnHidingToggle(0).click();
assertColumnHeaderOrder(0, 2, 3, 4, 5);
verifyColumnFrozen(0);
verifyColumnNotFrozen(0);
verifyColumnNotFrozen(1);
+ getSidebarOpenButton().click();
getColumnHidingToggle(0).click();
assertColumnHeaderOrder(0, 2, 3, 4, 5);
verifyColumnNotFrozen(0);