mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
PL-8218 The first menu item should not be selected on menu focus
This commit is contained in:
parent
cf73c05a55
commit
03f2185a3b
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user