From: Artur Signell Date: Mon, 25 Jun 2012 09:04:22 +0000 (+0300) Subject: Fixed tab index for Button and NativeButton (#9022) X-Git-Tag: 7.0.0.alpha3~68^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0fcade9ddfe7b624faa2e80e6138b5ac5c5ce950;p=vaadin-framework.git Fixed tab index for Button and NativeButton (#9022) --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/button/ButtonState.java b/src/com/vaadin/terminal/gwt/client/ui/button/ButtonState.java index fdc053b3ae..2daceea0e8 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/button/ButtonState.java +++ b/src/com/vaadin/terminal/gwt/client/ui/button/ButtonState.java @@ -5,6 +5,7 @@ package com.vaadin.terminal.gwt.client.ui.button; import com.vaadin.terminal.gwt.client.ComponentState; +import com.vaadin.terminal.gwt.client.ui.TabIndexState; import com.vaadin.ui.Button; /** @@ -14,9 +15,13 @@ import com.vaadin.ui.Button; * * @since 7.0 */ -public class ButtonState extends ComponentState { +public class ButtonState extends ComponentState implements TabIndexState { private boolean disableOnClick = false; private int clickShortcutKeyCode = 0; + /** + * The tab order number of this field. + */ + private int tabIndex = 0; /** * If caption should be rendered in HTML */ @@ -92,4 +97,22 @@ public class ButtonState extends ComponentState { return htmlContentAllowed; } + /* + * (non-Javadoc) + * + * @see com.vaadin.terminal.gwt.client.ui.TabIndexState#getTabIndex() + */ + public int getTabIndex() { + return tabIndex; + } + + /* + * (non-Javadoc) + * + * @see com.vaadin.terminal.gwt.client.ui.TabIndexState#setTabIndex(int) + */ + public void setTabIndex(int tabIndex) { + this.tabIndex = tabIndex; + } + } diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java index 8e504d828b..0abc50f26f 100644 --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@ -357,8 +357,6 @@ public class Button extends AbstractComponent implements protected ClickShortcut clickShortcut; - private int tabIndex = 0; - /** * Makes it possible to invoke a click on this button by pressing the given * {@link KeyCode} and (optional) {@link ModifierKey}s.
@@ -471,13 +469,23 @@ public class Button extends AbstractComponent implements requestRepaint(); } + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Component.Focusable#getTabIndex() + */ public int getTabIndex() { - return tabIndex; + return getState().getTabIndex(); } + /* + * (non-Javadoc) + * + * @see com.vaadin.ui.Component.Focusable#setTabIndex(int) + */ public void setTabIndex(int tabIndex) { - this.tabIndex = tabIndex; - + getState().setTabIndex(tabIndex); + requestRepaint(); } @Override diff --git a/tests/testbench/com/vaadin/tests/components/button/ButtonTabIndex.java b/tests/testbench/com/vaadin/tests/components/button/ButtonTabIndex.java new file mode 100644 index 0000000000..048e0698f3 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/button/ButtonTabIndex.java @@ -0,0 +1,53 @@ +/* +@VaadinApache2LicenseForJavaFiles@ + */ +package com.vaadin.tests.components.button; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.NativeButton; +import com.vaadin.ui.TextField; + +public class ButtonTabIndex extends TestBase { + + @Override + protected void setup() { + TextField tf1 = new TextField("Tab index 0"); + tf1.setTabIndex(0); + TextField tf2 = new TextField("Tab index -1, focused initially"); + tf2.setTabIndex(-1); + tf2.focus(); + addComponent(tf1); + addComponent(tf2); + + addComponent(createButton(1)); + addComponent(createButton(5)); + addComponent(createNativeButton(3)); + addComponent(createButton(4)); + addComponent(createNativeButton(2)); + + } + + private Button createButton(int i) { + Button b = new Button("Button with tab index " + i); + b.setTabIndex(i); + return b; + } + + private NativeButton createNativeButton(int i) { + NativeButton b = new NativeButton("NativeButton with tab index " + i); + b.setTabIndex(i); + return b; + } + + @Override + protected String getDescription() { + return "Test for tab indexes for Button and NativeButton"; + } + + @Override + protected Integer getTicketNumber() { + return 9022; + } + +}