diff options
author | Sergey Budkin <sergey@vaadin.com> | 2014-11-13 16:47:15 +0200 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-12-16 22:44:37 +0200 |
commit | a8a480cc92efb15c83833b4a87a0475b6802e57c (patch) | |
tree | f3795c80002a85164db45d55807300a5464997a4 | |
parent | 854644a8ccfb004e5ec5891def64628bc7a2e50e (diff) | |
download | vaadin-framework-a8a480cc92efb15c83833b4a87a0475b6802e57c.tar.gz vaadin-framework-a8a480cc92efb15c83833b4a87a0475b6802e57c.zip |
Accordion causes SEVERE error in browser console (#15182)
Refactored to remove invisible widgets from DOM.
Change-Id: I94d0ba37f4a75d71df88fbb0b1767ae60f39432d
3 files changed, 37 insertions, 19 deletions
diff --git a/client/src/com/vaadin/client/ui/VAccordion.java b/client/src/com/vaadin/client/ui/VAccordion.java index 3e89958a98..ff77a8cb91 100644 --- a/client/src/com/vaadin/client/ui/VAccordion.java +++ b/client/src/com/vaadin/client/ui/VAccordion.java @@ -159,6 +159,8 @@ public class VAccordion extends VTabsheetBase { */ public class StackItem extends ComplexPanel implements ClickHandler { + private Widget widget; + public void setHeight(int height) { if (height == -1) { super.setHeight(""); @@ -171,10 +173,7 @@ public class VAccordion extends VTabsheetBase { } public Widget getComponent() { - if (getWidgetCount() < 2) { - return null; - } - return getWidget(1); + return widget; } @Override @@ -268,24 +267,26 @@ public class VAccordion extends VTabsheetBase { } public Widget getChildWidget() { - if (getWidgetCount() > 1) { - return getWidget(1); - } else { - return null; - } + return widget; } public void replaceWidget(Widget newWidget) { - if (getWidgetCount() > 1) { - Widget oldWidget = getWidget(1); - remove(oldWidget); - widgets.remove(oldWidget); + if (widget != null) { + widgets.remove(widget); + if (open) { + remove(widget); + } } - add(newWidget, content); + widget = newWidget; widgets.add(newWidget); + if (open) { + add(widget, content); + } + } public void open() { + add(widget, content); open = true; content.getStyle().setTop(getCaptionHeight(), Unit.PX); content.getStyle().setLeft(0, Unit.PX); @@ -298,6 +299,9 @@ public class VAccordion extends VTabsheetBase { } public void close() { + if (widget != null) { + remove(widget); + } content.getStyle().setVisibility(Visibility.HIDDEN); content.getStyle().setTop(-100000, Unit.PX); content.getStyle().setLeft(-100000, Unit.PX); @@ -322,10 +326,10 @@ public class VAccordion extends VTabsheetBase { * new content */ public void setContent(Widget newWidget) { - if (getChildWidget() == null) { - add(newWidget, content); + if (widget == null) { + widget = newWidget; widgets.add(newWidget); - } else if (getChildWidget() != newWidget) { + } else if (widget != newWidget) { replaceWidget(newWidget); } if (isOpen() && isDynamicHeight()) { diff --git a/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java b/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java index c0caded759..72aa2dbdfd 100644 --- a/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java +++ b/client/src/com/vaadin/client/ui/accordion/AccordionConnector.java @@ -50,12 +50,13 @@ public class AccordionConnector extends TabsheetBaseConnector implements StackItem selectedItem = getWidget().getStackItem( getWidget().selectedItemIndex); - getWidget().open(getWidget().selectedItemIndex); - ComponentConnector contentConnector = getChildComponents().get(0); if (contentConnector != null) { selectedItem.setContent(contentConnector.getWidget()); } + + getWidget().open(getWidget().selectedItemIndex); + } else if (getWidget().getOpenStackItem() != null) { getWidget().close(getWidget().getOpenStackItem()); } diff --git a/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTabTest.java b/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTabTest.java index f5651e0ada..1047c070c8 100644 --- a/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTabTest.java +++ b/uitest/src/com/vaadin/tests/components/accordion/AccordionRemoveTabTest.java @@ -44,6 +44,19 @@ public class AccordionRemoveTabTest extends MultiBrowserTest { checkFirstItemHeight("On third tab"); } + @Test + public void testConsoleErrorOnSwitch() { + setDebug(true); + openTestURL(); + WebElement firstItem = driver.findElement(By + .className("v-accordion-item-first")); + WebElement caption = firstItem.findElement(By + .className("v-accordion-item-caption")); + caption.click(); + Assert.assertEquals("Errors present in console", 0, + findElements(By.className("SEVERE")).size()); + } + private void checkFirstItemHeight(String text) { WebElement firstItem = driver.findElement(By .className("v-accordion-item-first")); |