Reputation: 193
I have this problem with GWT: I need to skip a button from the focus cycle so I set the tab index to -1 with button.setTabIndex(-1), but in the generated html I get tabindex="0"... is this a bug?
Upvotes: 2
Views: 4176
Reputation: 1630
As with setFocus, use deferred:
Scheduler.get().scheduleDeferred(new Command() {
@Override
public void execute() {
cb.setTabIndex(-1);
}
});
Where in my case cb = CheckBox()
Upvotes: 0
Reputation:
Working with jsni. For example:
public static native void setElementTabIndex(Element b, int ti)/*-{
b.tabIndex = ti;
}-*/;
//and call the native js function
setElementTabIndex(odButton.getElement(), -1);
Upvotes: 0
Reputation: 64541
It looks like it's on-purpose: FocusWidget
's onAttach
resets the tab index to 0 in onAttach
when it was set to -1: https://gwt.googlesource.com/gwt/+/2.5.1/user/src/com/google/gwt/user/client/ui/FocusWidget.java
This behavior dates back to 3½ years ago (released in GWT 2.1.0): https://code.google.com/p/google-web-toolkit/source/detail?r=7642 so I'm surprised you're the first to report it (that I know of), but it indeed looks like a bug to me.
Upvotes: 3
Reputation: 202
It seems it is impossible to have a negative tabindex.
At first, the doc of setTabIndex
say :
Sets the widget's position in the tab index. If more than one widget has the same tab index, each such widget will receive focus in an arbitrary order. Setting the tab index to -1 will cause this widget to be removed from the tab order.
And w3c say :
Elements that may receive focus should be navigated by user agents according to the following rules:
Those elements that support the tabindex attribute and assign a positive value to it are navigated first. Navigation proceeds from the element with the lowest tabindex value to the element with the highest value. Values need not be sequential nor must they begin with any particular value. Elements that have identical tabindex values should be navigated in the order they appear in the character stream.
Those elements that do not support the tabindex attribute or support it and assign it a value of "0" are navigated next. These elements are navigated in the order they appear in the character stream.
Elements that are disabled do not participate in the tabbing order.
Source : http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#adef-tabindex
But if you want to skipe your button, try to set the tabindex < -1. Example :
Button myButton = new Button("Hello");
myButton.setTabIndex(-2);
// "-1" is convert to 0, and the button is not skipped
I try myButton.setTabIndex(-1);
and myButton.getElement.setAttribute("tabindex", "-1")
, that is always convert to 0 in html.
I wish that help you.
Upvotes: 2