diff options
author | Artur Signell <artur@vaadin.com> | 2016-04-16 16:43:59 +0300 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2016-04-28 15:18:39 +0000 |
commit | ab30dfe29d12e57d7c00c12cf2edc9328cb47a65 (patch) | |
tree | 7996d952bc3e57e79c6b4d3d7343bbc3dc1a347a | |
parent | 9006dbdf5a2d6d34d6322a8affc743087b5b46f5 (diff) | |
download | vaadin-framework-ab30dfe29d12e57d7c00c12cf2edc9328cb47a65.tar.gz vaadin-framework-ab30dfe29d12e57d7c00c12cf2edc9328cb47a65.zip |
Scroll selected tab into view (#3899)
Change-Id: I4e86caa4ad02dfc5d0eaa33b85f67da3837fcea0
3 files changed, 44 insertions, 1 deletions
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 e196870348..1ea41f634d 100644 --- a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java @@ -531,6 +531,9 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware public void selectTab(int index) { final Tab newSelected = getTab(index); final Tab oldSelected = selected; + if (oldSelected == newSelected) { + return; + } newSelected.setStyleNames(true, isFirstVisibleTab(index), true); newSelected.setTabulatorIndex(getTabsheet().tabulatorIndex); @@ -552,6 +555,10 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SubPartAware // The selected tab might need more (or less) space newSelected.recalculateCaptionWidth(); getTab(tabsheet.activeTabIndex).recalculateCaptionWidth(); + + // Scroll the tab into view if it is not already + getTabsheet().scrollIntoView(getTab(tabsheet.activeTabIndex)); + } public Tab navigateTab(int fromIndex, int toIndex) { diff --git a/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetScrolling.java b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetScrolling.java index da449a2461..fe1bcd0a1a 100644 --- a/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetScrolling.java +++ b/uitest/src/main/java/com/vaadin/tests/components/tabsheet/TabsheetScrolling.java @@ -9,6 +9,8 @@ import com.vaadin.ui.TabSheet.Tab; public class TabsheetScrolling extends TestBase { + public static final String SELECT_FIRST = "selFirst"; + public static final String SELECT_LAST = "selLast"; private TabSheet fixedSizeTabSheet; private TabSheet autoWideTabSheet; @@ -60,7 +62,28 @@ public class TabsheetScrolling extends TestBase { } addComponent(autoWideTabSheet); - + Button selectFirst = new Button("Select first tab in both tabsheets", + new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + fixedSizeTabSheet.setSelectedTab(0); + autoWideTabSheet.setSelectedTab(0); + } + }); + selectFirst.setId(SELECT_FIRST); + addComponent(selectFirst); + Button selectLast = new Button("Select last tab in both tabsheets", + new ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + int lastFixed = fixedSizeTabSheet.getComponentCount() - 1; + fixedSizeTabSheet.setSelectedTab(lastFixed); + int lastAuto = autoWideTabSheet.getComponentCount() - 1; + autoWideTabSheet.setSelectedTab(lastAuto); + } + }); + selectLast.setId(SELECT_LAST); + addComponent(selectLast); } @Override diff --git a/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollingTest.java b/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollingTest.java index 1da42bb1ce..47753e09d3 100644 --- a/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollingTest.java +++ b/uitest/src/test/java/com/vaadin/tests/components/tabsheet/TabsheetScrollingTest.java @@ -23,6 +23,7 @@ import org.openqa.selenium.interactions.Actions; import com.vaadin.testbench.By; import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.TabSheetElement; import com.vaadin.tests.tb3.MultiBrowserTest; public class TabsheetScrollingTest extends MultiBrowserTest { @@ -51,4 +52,16 @@ public class TabsheetScrollingTest extends MultiBrowserTest { new Actions(getDriver()).sendKeys(key).perform(); } + @Test + public void serverChangeShouldShowTab() { + openTestURL(); + $(ButtonElement.class).id(TabsheetScrolling.SELECT_LAST).click(); + TabSheetElement tabsheetFixed = $(TabSheetElement.class).first(); + Assert.assertTrue("Select last should scroll last tab into view", + tabsheetFixed.getTabCaptions().contains("Tab 99")); + $(ButtonElement.class).id(TabsheetScrolling.SELECT_FIRST).click(); + Assert.assertTrue("Select first should scroll first tab into view", + tabsheetFixed.getTabCaptions().contains("Tab 1")); + + } } |