summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnsku <Ansku@users.noreply.github.com>2017-11-10 16:50:27 +0200
committerPéter Török <31210544+torok-peter@users.noreply.github.com>2017-11-10 16:50:27 +0200
commitbcdd76c6a006a8d0f27f22c6078814ff2b4b09dc (patch)
tree117759e5ef9195ae9678ab5e33ca7be67d0b12fd
parent37bd6b1a32c9d5d6a53755de8bb1a94556b4471b (diff)
downloadvaadin-framework-bcdd76c6a006a8d0f27f22c6078814ff2b4b09dc.tar.gz
vaadin-framework-bcdd76c6a006a8d0f27f22c6078814ff2b4b09dc.zip
Fix setting custom tab index for TabSheet or Accordion (#9574) (#10278)
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VAccordion.java18
-rw-r--r--client/src/main/java/com/vaadin/client/ui/VTabsheet.java14
-rw-r--r--shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabsheetState.java1
-rw-r--r--uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java9
-rw-r--r--uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java23
5 files changed, 58 insertions, 7 deletions
diff --git a/client/src/main/java/com/vaadin/client/ui/VAccordion.java b/client/src/main/java/com/vaadin/client/ui/VAccordion.java
index 9ad4ef4e96..c103f9e726 100644
--- a/client/src/main/java/com/vaadin/client/ui/VAccordion.java
+++ b/client/src/main/java/com/vaadin/client/ui/VAccordion.java
@@ -51,6 +51,8 @@ public class VAccordion extends VTabsheetBase {
private final TouchScrollHandler touchScrollHandler;
+ private int tabulatorIndex;
+
public VAccordion() {
super(CLASSNAME);
@@ -110,6 +112,20 @@ public class VAccordion extends VTabsheetBase {
}
}
+ /**
+ * For internal use only. May be renamed or removed in a future release.
+ *
+ * @param tabIndex
+ * tabulator index for the open stack item
+ */
+ public void setTabIndex(int tabIndex) {
+ tabulatorIndex = tabIndex;
+ StackItem openStackItem = getOpenStackItem();
+ if (openStackItem != null) {
+ openStackItem.getElement().setTabIndex(tabIndex);
+ }
+ }
+
/** For internal use only. May be removed or replaced in the future. */
public void open(int itemIndex) {
StackItem item = (StackItem) getWidget(itemIndex);
@@ -308,6 +324,7 @@ public class VAccordion extends VTabsheetBase {
content.getStyle().setLeft(0, Unit.PX);
content.getStyle().clearVisibility();
addStyleDependentName("open");
+ getElement().setTabIndex(tabulatorIndex);
}
public void hide() {
@@ -325,6 +342,7 @@ public class VAccordion extends VTabsheetBase {
setHeight(-1);
setWidth("");
open = false;
+ getElement().setTabIndex(-1);
}
public boolean isOpen() {
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 e3e55f97ef..c9c721bbe9 100644
--- a/client/src/main/java/com/vaadin/client/ui/VTabsheet.java
+++ b/client/src/main/java/com/vaadin/client/ui/VTabsheet.java
@@ -787,6 +787,20 @@ public class VTabsheet extends VTabsheetBase
private String currentStyle;
/**
+ * For internal use only. May be renamed or removed in a future release.
+ *
+ * @param tabIndex
+ * tabulator index for the active tab of the tab sheet
+ */
+ public void setTabIndex(int tabIndex) {
+ tabulatorIndex = tabIndex;
+ Tab activeTab = getActiveTab();
+ if (activeTab != null) {
+ activeTab.setTabulatorIndex(tabIndex);
+ }
+ }
+
+ /**
* @return Whether the tab could be selected or not.
*/
private boolean canSelectTab(final int tabIndex) {
diff --git a/shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabsheetState.java b/shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabsheetState.java
index 3af0da9b42..6f8f7bfd84 100644
--- a/shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabsheetState.java
+++ b/shared/src/main/java/com/vaadin/shared/ui/tabsheet/TabsheetState.java
@@ -34,6 +34,7 @@ public class TabsheetState extends AbstractComponentContainerState {
* tabs.
*/
@NoLayout
+ @DelegateToWidget
public int tabIndex;
public List<TabState> tabs = new ArrayList<>();
diff --git a/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java b/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java
index df93a43a37..179a512403 100644
--- a/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java
+++ b/uitest/src/main/java/com/vaadin/tests/fields/TabIndexes.java
@@ -6,6 +6,7 @@ import java.util.List;
import com.vaadin.annotations.Widgetset;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUIWithLog;
+import com.vaadin.ui.Accordion;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
@@ -13,12 +14,14 @@ import com.vaadin.ui.Component;
import com.vaadin.ui.DateField;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.InlineDateField;
+import com.vaadin.ui.Label;
import com.vaadin.ui.ListSelect;
import com.vaadin.ui.MenuBar;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.PasswordField;
import com.vaadin.ui.RichTextArea;
import com.vaadin.ui.Slider;
+import com.vaadin.ui.TabSheet;
import com.vaadin.ui.TextArea;
import com.vaadin.ui.TextField;
import com.vaadin.ui.TreeGrid;
@@ -54,6 +57,12 @@ public class TabIndexes extends AbstractTestUIWithLog {
menubar.addItem("foo", item -> {
});
fields.add(menubar);
+ TabSheet tabSheet = new TabSheet();
+ tabSheet.addTab(new Label("Tab content"), "Tab 1");
+ fields.add(tabSheet);
+ Accordion accordion = new Accordion();
+ accordion.addTab(new Label("Tab content"), "Tab 1");
+ fields.add(accordion);
HorizontalLayout buttonLayout = new HorizontalLayout();
addComponent(buttonLayout);
diff --git a/uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java b/uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java
index db61d72d8f..67f7bea44f 100644
--- a/uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java
+++ b/uitest/src/test/java/com/vaadin/tests/fields/TabIndexesTest.java
@@ -8,7 +8,9 @@ import java.util.List;
import org.junit.Test;
import org.openqa.selenium.WebElement;
+import com.vaadin.testbench.By;
import com.vaadin.testbench.elements.AbstractComponentElement;
+import com.vaadin.testbench.elements.AccordionElement;
import com.vaadin.testbench.elements.ButtonElement;
import com.vaadin.testbench.elements.CheckBoxElement;
import com.vaadin.testbench.elements.ComboBoxElement;
@@ -20,6 +22,7 @@ import com.vaadin.testbench.elements.NativeSelectElement;
import com.vaadin.testbench.elements.PasswordFieldElement;
import com.vaadin.testbench.elements.RichTextAreaElement;
import com.vaadin.testbench.elements.SliderElement;
+import com.vaadin.testbench.elements.TabSheetElement;
import com.vaadin.testbench.elements.TextAreaElement;
import com.vaadin.testbench.elements.TextFieldElement;
import com.vaadin.testbench.elements.TreeGridElement;
@@ -85,12 +88,10 @@ public class TabIndexesTest extends SingleBrowserTest {
}
private void assertTabIndex(String expected, WebElement element) {
- if (!expected.equals(element.getAttribute("tabIndex"))) {
- assertEquals(
- "Unexpected tab index for element "
- + element.getAttribute("outerHTML"),
- expected, element.getAttribute("tabIndex"));
- }
+ assertEquals(
+ "Unexpected tab index for element "
+ + element.getAttribute("outerHTML"),
+ expected, element.getAttribute("tabIndex"));
}
private List<WebElement> getFocusElements() {
@@ -115,11 +116,19 @@ public class TabIndexesTest extends SingleBrowserTest {
focusElements.add($(CheckBoxElement.class).first().getInputElement());
focusElements.add($(SliderElement.class).first());
focusElements.add($(MenuBarElement.class).first());
+ TabSheetElement tabsheet = $(TabSheetElement.class).first();
+ focusElements.add(tabsheet
+ .findElement(By.className("v-tabsheet-tabitemcell-selected")));
+ AccordionElement accordion = $(AccordionElement.class).first();
+ focusElements.add(
+ accordion.findElement(By.className("v-accordion-item-open")));
List<AbstractComponentElement> components = $(
VerticalLayoutElement.class).id(TabIndexes.FIELD_CONTAINER_ID)
.$(AbstractComponentElement.class).all();
- assertEquals(components.size(), focusElements.size());
+ // the Labels within the TabSheet and Accordion are left out of the
+ // index handling
+ assertEquals(components.size(), focusElements.size() + 2);
return focusElements;
}