]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixing TabSheet scrolling within SplitPanel (#20052)
authoradam <adam@vaadin.com>
Mon, 18 Jul 2016 13:21:52 +0000 (16:21 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 3 Aug 2016 09:57:31 +0000 (09:57 +0000)
This patch fixes an issue with disappearing tabs in a TabSheet placed in a
SplitPanel.

Scrolling a tab into view needs to be done after layout has happened. Otherwise
the available width for TabSheet is unknown and causes unexpected behaviour.

Change-Id: Ibcea04ddadfafc5028efe44a6817517b16e21bde

client/src/main/java/com/vaadin/client/ui/VTabsheet.java
uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetScrollIntoView.java [new file with mode: 0644]
uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollIntoViewTest.java [new file with mode: 0644]

index 1ea41f634da960ebf52cebf44b0734b20ab49167..9b1608cb65658350dfd82ec4eadf3c061c61f7ee 100644 (file)
@@ -556,9 +556,14 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware
             newSelected.recalculateCaptionWidth();
             getTab(tabsheet.activeTabIndex).recalculateCaptionWidth();
 
-            // Scroll the tab into view if it is not already
-            getTabsheet().scrollIntoView(getTab(tabsheet.activeTabIndex));
-
+            // Scroll the tab into view if it is not already, after layout
+            Scheduler.get().scheduleFinally(new Scheduler.ScheduledCommand() {
+                @Override
+                public void execute() {
+                    getTabsheet()
+                            .scrollIntoView(getTab(tabsheet.activeTabIndex));
+                }
+            });
         }
 
         public Tab navigateTab(int fromIndex, int toIndex) {
diff --git a/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetScrollIntoView.java b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetScrollIntoView.java
new file mode 100644 (file)
index 0000000..4b68dd6
--- /dev/null
@@ -0,0 +1,81 @@
+package com.vaadin.tests.components.tabsheet;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Button.ClickEvent;
+import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.HorizontalSplitPanel;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Layout;
+import com.vaadin.ui.TabSheet;
+import com.vaadin.ui.VerticalLayout;
+
+public class TabsheetScrollIntoView extends AbstractTestUI {
+
+    public static final String BTN_SELECT_LAST_TAB = "showAndSelectLastTab";
+
+    private TabSheet tabSheetInSplitPanel;
+    private HorizontalSplitPanel panel = new HorizontalSplitPanel();
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        panel.setHeight("200px");
+        tabSheetInSplitPanel = new TabSheet();
+        tabSheetInSplitPanel.setWidth(100, Unit.PERCENTAGE);
+        for (int i = 0; i < 100; i++) {
+            tabSheetInSplitPanel.addTab(new Label("Tab " + i), "Tab " + i);
+        }
+
+        Layout buttonLayout = new VerticalLayout();
+
+        buttonLayout
+                .addComponent(new Button("Hide TabSheet", new ClickListener() {
+
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        panel.setSplitPosition(100, Unit.PERCENTAGE);
+                        panel.removeComponent(tabSheetInSplitPanel);
+                    }
+                }));
+
+        Button showLast = new Button("Show TabSheet and select last tab",
+                new ClickListener() {
+
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        panel.setSecondComponent(tabSheetInSplitPanel);
+                        panel.setSplitPosition(250, Unit.PIXELS);
+                        tabSheetInSplitPanel.setSelectedTab(
+                                tabSheetInSplitPanel.getComponentCount() - 1);
+                    }
+                });
+        showLast.setId(BTN_SELECT_LAST_TAB);
+        buttonLayout.addComponent(showLast);
+
+        buttonLayout.addComponent(new Button(
+                "Show TabSheet and select first tab", new ClickListener() {
+
+                    @Override
+                    public void buttonClick(ClickEvent event) {
+                        panel.setSecondComponent(tabSheetInSplitPanel);
+                        panel.setSplitPosition(250, Unit.PIXELS);
+                        tabSheetInSplitPanel.setSelectedTab(0);
+                    }
+                }));
+
+        panel.setFirstComponent(buttonLayout);
+        panel.setSplitPosition(100, Unit.PERCENTAGE);
+        addComponent(panel);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Clicking \"Show TabSheet and select last tab\" should scroll to the last tab and not disable tab scrolling.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 20052;
+    }
+}
diff --git a/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollIntoViewTest.java b/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollIntoViewTest.java
new file mode 100644 (file)
index 0000000..8e10785
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.tabsheet;
+
+import java.util.List;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.testbench.elements.ButtonElement;
+import com.vaadin.testbench.elements.TabSheetElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class TabsheetScrollIntoViewTest extends MultiBrowserTest {
+
+    @Test
+    public void scrollIntoView() {
+        openTestURL();
+
+        $(ButtonElement.class).id(TabsheetScrollIntoView.BTN_SELECT_LAST_TAB)
+                .click();
+        TabSheetElement tabSheet = $(TabSheetElement.class).first();
+        Assert.assertTrue("Select last should not hide other tabs",
+                tabSheet.getTabCaptions().contains("Tab 98"));
+
+        List<WebElement> scrollerPrev = tabSheet
+                .findElements(By.className("v-tabsheet-scrollerPrev"));
+        Assert.assertTrue("Select last should not disable tab scrolling",
+                !scrollerPrev.isEmpty() && scrollerPrev.get(0).isDisplayed());
+    }
+
+}