aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Fansky <alexey.fansky@effective-soft.com>2014-12-10 15:52:46 -0800
committerVaadin Code Review <review@vaadin.com>2014-12-11 07:57:07 +0000
commit5eaf32a1404399f7b39f3b60060ed3d101ec08f8 (patch)
treebe1c15287e4ae0f1f08cb43a24dee5837cd1517a
parentc4e4f449464f22c11e33b92f8aa578db959e92b2 (diff)
downloadvaadin-framework-5eaf32a1404399f7b39f3b60060ed3d101ec08f8.tar.gz
vaadin-framework-5eaf32a1404399f7b39f3b60060ed3d101ec08f8.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
-rw-r--r--client/src/com/vaadin/client/ui/VTabsheet.java27
-rw-r--r--uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleInTabsheet.java44
-rw-r--r--uitest/src/com/vaadin/tests/components/tabsheet/FirstTabNotVisibleInTabsheetTest.java27
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 bcca117395..090f83c066 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;
@@ -1069,6 +1071,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);
@@ -1080,10 +1098,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);
}
@@ -1223,7 +1246,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();
+ }
+}