gwt-material
gwt-material copied to clipboard
GMD 2.0: MaterialTab returns wrong tab index
I just upgraded to 2.0 and tried the MaterialTab widget (haven't used it before). I noticed a strange behavior: I have a MaterialTab with 6 tab items (which in turn contain links). If I query the selected tab with getTabIndex()
I get 0 (zero) for the first item (as expected) but for all further items I get a 1-based index, i.e. 2 for the second etc. getTabIndex()
uses the JQuery code $(getElement()).find("li:has(a.active)").index()
to retrieve the index but if I inspect the DOM I see the expected structure: a parent ul
"tabs" with 6 child li
containing anchors of which only one has the active
class.
The problem is even reproducable if I execute the JQuery code $("ul.tabs").find("li:has(a.active)").index()
in the browser console. Could it be that the JQuery version in GMD2.0 has a bug?
Hi @javafh, can you share with us a sample code where in you created your tabs. As per the testing , the junit passed with this usecase and also upon playing it into the demo (Tabs) , we don't see any issue.https://gwtmaterialdesign.github.io/gwt-material-demo/#tabs
This bug was reported by me, I was logged in with a different account. Giving a code example is difficult because GMD is wrapped by my own framework. But I found the reason for the effect, it is some kind of lazy initialization problem. In my DOM the tab indicator was inserted after the first tab item, thus increasing the index determined by JQuery by 1 for all successive tab items. I couldn't determine how exactly this is caused but if tabs are added after attaching the current update mechanism with unload/load doesn't seem to work correctly. I fixed this by overriding the method load()
to contain the following code:
public void load()
{
JsMaterialElement.$(getElement()).find(".indicator").remove();
super.load();
}
If the indicator is not removed first the call to $(getElement()).tabs()
in the original load method will keep an existing indicator before any new children although a reload is initiated by add(Widget)
. By the way, the name of clearAllIndicators()
is misleading because it doesn't clear all indicators, but only any additional ones besides the first. Furthermore it is not clear to me why this method uses scheduleDeferred()
for such a simple task.
You closed this - are you re-opening or should I create a new issue?