Revision: 7635
Author: j...@google.com
Date: Mon Mar 1 09:49:01 2010
Log: Fix to keep FocusWidget's setElement() implementation from clobbering
tabindex when it's already set. This comes up in practice when calling,
e.g.,
TextBox.wrap() on a static element that already had a perfectly good
tabindex.
Review at http://gwt-code-reviews.appspot.com/153815
http://code.google.com/p/google-web-toolkit/source/detail?r=7635
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/FocusWidget.java
/trunk/user/test/com/google/gwt/user/client/ui/TextBoxTest.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/FocusWidget.java Fri Mar
20 11:33:42 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/FocusWidget.java Mon Mar
1 09:49:01 2010
@@ -272,7 +272,8 @@
// any calls made to FocusWidget.setTabIndex(int) by user code, because
// FocusWidget.setTabIndex(int) cannot be called until setElement(elem)
// has been called.
- setTabIndex(0);
- }
-
-}
+ if (-1 == getTabIndex()) {
+ setTabIndex(0);
+ }
+ }
+}
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/TextBoxTest.java Fri
Apr 4 09:22:37 2008
+++ /trunk/user/test/com/google/gwt/user/client/ui/TextBoxTest.java Mon
Mar 1 09:49:01 2010
@@ -15,6 +15,9 @@
*/
package com.google.gwt.user.client.ui;
+import com.google.gwt.dom.client.DivElement;
+import com.google.gwt.dom.client.Document;
+
/**
* Testing TextBox.
*/
@@ -32,7 +35,7 @@
// As our setText does not honor max length, no way to text it in the
wild
// here.
}
-
+
public void testMinLength() {
TextBox b = createTextBoxBase();
b.setVisibleLength(5);
@@ -44,4 +47,14 @@
// Now check visible length.
assertEquals(5, b.getVisibleLength());
}
-}
+
+ public void testNoNukeTabIndex() {
+ Document doc = Document.get();
+ DivElement div = doc.createDivElement();
+ div.setInnerHTML("<input type='text' id='tb' tabindex='1'></input>");
+ doc.getBody().appendChild(div);
+
+ TextBox tb = TextBox.wrap(doc.getElementById("tb"));
+ assertEquals(1, tb.getTabIndex());
+ }
+}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors