PL-8218 The first menu item should not be selected on menu focus

This commit is contained in:
Yuriy Artamonov 2016-11-16 13:21:33 +04:00
parent cf73c05a55
commit 03f2185a3b

View File

@ -17,25 +17,13 @@
package com.haulmont.cuba.web.toolkit.ui.client.menubar;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.vaadin.client.UIDL;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.ui.Icon;
import com.vaadin.client.ui.VMenuBar;
public class CubaMenuBarWidget extends VMenuBar implements BlurHandler {
protected boolean mouseEvent = false;
public class CubaMenuBarWidget extends VMenuBar {
public CubaMenuBarWidget() {
addBlurHandler(this);
DOM.sinkEvents(getElement(), DOM.getEventsSunk(getElement()) | Event.ONMOUSEDOWN);
}
@Override
@ -91,59 +79,4 @@ public class CubaMenuBarWidget extends VMenuBar implements BlurHandler {
}
return itemHTML.toString();
}
@Override
public void onBrowserEvent(Event e) {
// select first item only on keyboard focus events
if (e.getTypeInt() == Event.ONMOUSEDOWN) {
mouseEvent = true;
}
super.onBrowserEvent(e);
}
protected void selectFirstItem() {
for (CustomMenuItem item : items) {
if (item.isSelectable()) {
setSelected(item);
break;
}
}
}
@Override
public void onMenuClick(int clickedItemId) {
super.onMenuClick(clickedItemId);
mouseEvent = true;
}
@Override
public void onFocus(FocusEvent event) {
super.onFocus(event);
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
// select first item only on keyboard focus events
if (getSelected() == null && !mouseEvent) {
selectFirstItem();
}
mouseEvent = false;
}
});
addStyleDependentName("focus");
}
@Override
public void onBlur(BlurEvent event) {
removeStyleDependentName("focus");
mouseEvent = false;
if (!menuVisible) {
setSelected(null);
}
}
}