From: adam Date: Mon, 18 Jul 2016 13:21:52 +0000 (+0300) Subject: Fixing TabSheet scrolling within SplitPanel (#20052) X-Git-Tag: 7.7.0.rc1~7 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=35078caabebfda612867c68b38f1d554dd3192a7;p=vaadin-framework.git Fixing TabSheet scrolling within SplitPanel (#20052) 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 --- diff --git a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java index 1ea41f634d..9b1608cb65 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java @@ -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 index 0000000000..4b68dd61af --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetScrollIntoView.java @@ -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 index 0000000000..8e107859e5 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollIntoViewTest.java @@ -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 scrollerPrev = tabSheet + .findElements(By.className("v-tabsheet-scrollerPrev")); + Assert.assertTrue("Select last should not disable tab scrolling", + !scrollerPrev.isEmpty() && scrollerPrev.get(0).isDisplayed()); + } + +}