]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed TabSheet tab focusing (#13206)
authorJuho Nurminen <juho@vaadin.com>
Fri, 24 Jan 2014 14:40:19 +0000 (16:40 +0200)
committerVaadin Code Review <review@vaadin.com>
Fri, 31 Jan 2014 10:54:48 +0000 (10:54 +0000)
Change-Id: Ice0988a281504be3b304be3be6c09e2e2c5be4ba

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

index 33ac8e27ad46c20fa072c6e3d5b53586624eeb1a..81786f26474920c2ecf362772a82d42540cfea83 100644 (file)
@@ -486,6 +486,9 @@ public class VTabsheet extends VTabsheetBase implements Focusable,
 
             int index = getWidgetIndex(caption.getParent());
 
+            navigateTab(getTabsheet().focusedTabIndex, index);
+            getTabsheet().focusedTabIndex = index;
+            getTabsheet().focusedTab = getTab(index);
             getTabsheet().focus();
             getTabsheet().loadTabSheet(index);
         }
@@ -700,15 +703,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable,
         if (activeTabIndex != tabIndex && canSelectTab(tabIndex)) {
             tb.selectTab(tabIndex);
 
-            // If this TabSheet already has focus, set the new selected tab
-            // as focused.
-            if (focusedTab != null) {
-                focusedTab = tb.getTab(tabIndex);
-                focusedTab.focus();
-            }
-
             activeTabIndex = tabIndex;
-            focusedTabIndex = tabIndex;
 
             addStyleDependentName("loading");
             // Hide the current contents so a loading indicator can be shown
diff --git a/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetFocusedTabTest.java b/uitest/src/com/vaadin/tests/components/tabsheet/TabSheetFocusedTabTest.java
new file mode 100644 (file)
index 0000000..81648c1
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2000-2013 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 static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.interactions.Actions;
+
+import com.vaadin.testbench.By;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class TabSheetFocusedTabTest extends MultiBrowserTest {
+
+    @Override
+    protected Class<?> getUIClass() {
+        return TabsheetScrolling.class;
+    }
+
+    @Test
+    public void clickingChangesFocusedTab() throws Exception {
+        openTestURL();
+
+        getTab(1).click();
+
+        assertTrue(isFocused(getTab(1)));
+
+        new Actions(getDriver()).sendKeys(Keys.RIGHT).perform();
+
+        assertFalse(isFocused(getTab(1)));
+        assertTrue(isFocused(getTab(3)));
+
+        getTab(5).click();
+
+        assertFalse(isFocused(getTab(3)));
+        assertTrue(isFocused(getTab(5)));
+
+        getTab(1).click();
+
+        assertFalse(isFocused(getTab(5)));
+        assertTrue(isFocused(getTab(1)));
+    }
+
+    private WebElement getTab(int index) {
+        return getDriver()
+                .findElement(
+                        By.xpath("(//table[contains(@class, 'v-tabsheet-tabs')])[1]/tbody/tr/td["
+                                + (index + 1) + "]/div"));
+    }
+
+    private boolean isFocused(WebElement tab) {
+        return tab.getAttribute("class").contains("v-tabsheet-tabitem-focus");
+    }
+
+}