diff options
author | Juho Nurminen <juho@vaadin.com> | 2013-10-31 15:38:51 +0200 |
---|---|---|
committer | Juho Nurminen <juho@vaadin.com> | 2013-11-20 19:28:11 +0200 |
commit | 9ab700417ee5fe54329beee3130e6303f9420389 (patch) | |
tree | 1c126f6351cfd6543cc357dd7d5703a6fe431ad7 | |
parent | b7e184e30f8e5f1456344f3360c7e8e326c5ad2b (diff) | |
download | vaadin-framework-9ab700417ee5fe54329beee3130e6303f9420389.tar.gz vaadin-framework-9ab700417ee5fe54329beee3130e6303f9420389.zip |
Fixed TabSheet tab keyboard focus issues (#12343)
Change-Id: Ifacf4208e5124665115d13928463d87922282461
-rw-r--r-- | client/src/com/vaadin/client/ui/VTabsheet.java | 58 |
1 files changed, 34 insertions, 24 deletions
diff --git a/client/src/com/vaadin/client/ui/VTabsheet.java b/client/src/com/vaadin/client/ui/VTabsheet.java index 85c28218f7..1275308ed7 100644 --- a/client/src/com/vaadin/client/ui/VTabsheet.java +++ b/client/src/com/vaadin/client/ui/VTabsheet.java @@ -118,7 +118,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, setStyleName(td, TD_CLASSNAME); div = DOM.createDiv(); - focusImpl.setTabIndex(td, -1); + setTabulatorIndex(-1); setStyleName(div, DIV_CLASSNAME); DOM.appendChild(td, div); @@ -182,7 +182,7 @@ public class VTabsheet extends VTabsheetBase implements Focusable, } public void setTabulatorIndex(int tabIndex) { - focusImpl.setTabIndex(td, tabIndex); + getElement().setTabIndex(tabIndex); } public boolean isClosable() { @@ -249,6 +249,17 @@ public class VTabsheet extends VTabsheetBase implements Focusable, public void blur() { focusImpl.blur(td); } + + public boolean isSelectable() { + VTabsheet ts = getTabsheet(); + if (ts.client == null || ts.disabled || ts.waitingForResponse) { + return false; + } + if (!isEnabledOnServer() || isHiddenOnServer()) { + return false; + } + return true; + } } public static class TabCaption extends VCaption { @@ -585,24 +596,14 @@ public class VTabsheet extends VTabsheetBase implements Focusable, private String currentStyle; - /** - * @return Whether the tab could be selected or not. - */ - private boolean onTabSelected(final int tabIndex) { - Tab tab = tb.getTab(tabIndex); - if (client == null || disabled || waitingForResponse) { - return false; - } - if (!tab.isEnabledOnServer() || tab.isHiddenOnServer()) { - return false; - } + private void onTabSelected(final int tabIndex) { if (activeTabIndex != tabIndex) { tb.selectTab(tabIndex); // If this TabSheet already has focus, set the new selected tab // as focused. if (focusedTab != null) { - focusedTab = tab; + focusedTab = tb.getTab(tabIndex); } addStyleDependentName("loading"); @@ -618,9 +619,6 @@ public class VTabsheet extends VTabsheetBase implements Focusable, tb.getTab(tabIndex).focus(); // move keyboard focus to active tab } - // Note that we return true when tabIndex == activeTabIndex; the active - // tab could be selected, it's just a no-op. - return true; } public ApplicationConnection getApplicationConnection() { @@ -979,6 +977,13 @@ public class VTabsheet extends VTabsheetBase implements Focusable, SCROLLER_CLASSNAME + (scrolled ? "Prev" : "Prev-disabled")); DOM.setElementProperty(scrollerNext, "className", SCROLLER_CLASSNAME + (clipped ? "Next" : "Next-disabled")); + + // the active tab should be focusable if and only if it is visible + boolean isActiveTabVisible = scrollerIndex <= activeTabIndex + && !isClipped(tb.selected); + tb.selected.setTabulatorIndex(isActiveTabVisible ? tabulatorIndex + : -1); + } else { DOM.setStyleAttribute(scroller, "display", "none"); } @@ -1155,42 +1160,47 @@ public class VTabsheet extends VTabsheetBase implements Focusable, private void selectPreviousTab() { int newTabIndex = activeTabIndex; + Tab newTab; // Find the previous visible and enabled tab if any. do { newTabIndex--; - } while (newTabIndex >= 0 && !onTabSelected(newTabIndex)); + newTab = tb.getTab(newTabIndex); + } while (newTabIndex >= 0 && !newTab.isSelectable()); if (newTabIndex >= 0) { - activeTabIndex = newTabIndex; if (isScrolledTabs()) { // Scroll until the new active tab is visible - while (!tb.getTab(activeTabIndex).isVisible()) { + while (!newTab.isVisible()) { scrollerIndex = tb.scrollLeft(scrollerIndex); } updateTabScroller(); } + onTabSelected(newTabIndex); + activeTabIndex = newTabIndex; } } private void selectNextTab() { int newTabIndex = activeTabIndex; + Tab newTab; // Find the next visible and enabled tab if any. do { newTabIndex++; - } while (newTabIndex < getTabCount() && !onTabSelected(newTabIndex)); + newTab = tb.getTab(newTabIndex); + } while (newTabIndex < getTabCount() && !newTab.isSelectable()); if (newTabIndex < getTabCount()) { - activeTabIndex = newTabIndex; if (isClippedTabs()) { // Scroll until the new active tab is completely visible int newScrollerIndex = scrollerIndex; - while (isClipped(tb.getTab(activeTabIndex)) - && newScrollerIndex != -1) { + while (isClipped(newTab) && newScrollerIndex != -1) { newScrollerIndex = tb.scrollRight(newScrollerIndex); } scrollerIndex = newScrollerIndex; updateTabScroller(); } + onTabSelected(newTabIndex); + activeTabIndex = newTabIndex; } } } |