diff options
author | Alexey Fansky <alexey.fansky@effective-soft.com> | 2014-12-10 15:52:46 -0800 |
---|---|---|
committer | Sauli Tähkäpää <sauli@vaadin.com> | 2014-12-16 22:57:53 +0200 |
commit | 8b58a7e6b4e4ded405de8698d6dba0884affa3f1 (patch) | |
tree | 3e01efb9141c4c53fd4d6089b10250d08fe7dd10 | |
parent | 6a9f18e592c9bd99e90d3886f96beaab6df7d064 (diff) | |
download | vaadin-framework-8b58a7e6b4e4ded405de8698d6dba0884affa3f1.tar.gz vaadin-framework-8b58a7e6b4e4ded405de8698d6dba0884affa3f1.zip |
Reset tabsheet scroller when unhiding leftmost tab (#14644)
Checking whether invisible tab are present before the scroll index and
if so resetting the scroll index when tab goes back to visible.
Change-Id: I156dbe93963b0d9f46e21a593ffc3c4c77ebd1c6
3 files changed, 96 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/ui/VTabsheet.java b/client/src/com/vaadin/client/ui/VTabsheet.java index 745f2bca61..d5cbc5eb14 100644 --- a/client/src/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/VTabsheet.java @@ -78,6 +78,8 @@ import com.vaadin.shared.ui.tabsheet.TabsheetState; public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware { + private static final String PREV_SCROLLER_DISABLED_CLASSNAME = "Prev-disabled"; + private static class VCloseEvent { private Tab tab; @@ -1016,6 +1018,22 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware updateOpenTabSize(); } + private boolean isAllTabsBeforeIndexInvisible() { + boolean invisible = true; + for (int i = 0; i < scrollerIndex; i++) { + invisible = invisible & !tb.getTab(i).isVisible(); + } + return invisible; + } + + private boolean isScrollerPrevDisabled() { + return scrollerPrev.getClassName().contains(PREV_SCROLLER_DISABLED_CLASSNAME); + } + + private boolean isIndexSkippingHiddenTabs() { + return isAllTabsBeforeIndexInvisible() && isScrollerPrevDisabled(); + } + @Override public void renderTab(final TabState tabState, int index) { Tab tab = tb.getTab(index); @@ -1027,10 +1045,15 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware tab.setEnabledOnServer((!disabledTabKeys.contains(tabKeys.get(index)))); tab.setHiddenOnServer(!tabState.visible); - if (scrolledOutOfView(index)) { + if (scrolledOutOfView(index) && !isIndexSkippingHiddenTabs()) { // Should not set tabs visible if they are scrolled out of view tab.setVisible(false); } else { + //reset the scroller index back to zero if tab is visible + //again and tab is in view + if(isIndexSkippingHiddenTabs() && tabState.visible) { + scrollerIndex = 0; + } tab.setVisible(tabState.visible); } @@ -1170,7 +1193,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware if (tb.getTabCount() > 0 && tb.isVisible() && (scrolled || clipped)) { scroller.getStyle().clearDisplay(); DOM.setElementProperty(scrollerPrev, "className", - SCROLLER_CLASSNAME + (scrolled ? "Prev" : "Prev-disabled")); + SCROLLER_CLASSNAME + (scrolled ? "Prev" : PREV_SCROLLER_DISABLED_CLASSNAME)); DOM.setElementProperty(scrollerNext, "className", SCROLLER_CLASSNAME + (clipped ? "Next" : "Next-disabled")); diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleInTabsheet.java b/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleInTabsheet.java new file mode 100644 index 0000000000..c21c702bd0 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleInTabsheet.java @@ -0,0 +1,44 @@ +package com.vaadin.tests.components.tabsheet; + +import com.vaadin.annotations.VaadinServletConfiguration; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinServlet; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.*; + +import javax.servlet.annotation.WebServlet; + +@SuppressWarnings("serial") +public class FirstTabNotVisibleInTabsheet extends AbstractTestUI { + + private TabSheet.Tab firstTab; + + @Override + protected void setup(VaadinRequest request) { + TabSheet tabSheet = new TabSheet(); + tabSheet.setWidth("600px"); + + firstTab = tabSheet.addTab(new Label("first visible tab"), "first visible tab"); + + for (int i = 2; i < 10; i++) { + tabSheet.addTab(new Label("visible tab " + i), "visible tab " + i); + } + + addComponent(new VerticalLayout(tabSheet, new Button("Toggle first tab", new Button.ClickListener() { + @Override + public void buttonClick(Button.ClickEvent event) { + firstTab.setVisible(!firstTab.isVisible()); + } + }))); + } + + @Override + protected Integer getTicketNumber() { + return 14644; + } + + @Override + protected String getTestDescription() { + return "First tabsheet tab is not set visible back once it gets invisible"; + } +}
\ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleInTabsheetTest.java b/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleInTabsheetTest.java new file mode 100644 index 0000000000..e57651ba03 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleInTabsheetTest.java @@ -0,0 +1,27 @@ +package com.vaadin.tests.components.tabsheet; + + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TabSheetElement; +import com.vaadin.tests.tb3.MultiBrowserTest; +import junit.framework.Assert; +import org.junit.Test; + +public class FirstTabNotVisibleInTabsheetTest extends MultiBrowserTest { + @Test + public void testFirstTabIsVisibleAfterBeingInvisible() { + openTestURL(); + + toggleFirstTabVisibility(); + toggleFirstTabVisibility(); + + TabSheetElement tabSheet = $(TabSheetElement.class).first(); + + Assert.assertTrue("TabSheet should have first tab visible", + tabSheet.getTabCaptions().contains("first visible tab")); + } + + private void toggleFirstTabVisibility() { + $(ButtonElement.class).caption("Toggle first tab").first().click(); + } +} |