From 12fe44d807404343c24caee5a1fc53ec031449c5 Mon Sep 17 00:00:00 2001 From: Anastasia Smirnova Date: Mon, 17 Dec 2018 14:55:09 +0200 Subject: Improve VMenuBar click handling logic (#11356) * Improve VMenuBar click handling logic During `updateFromUIDL` inside MenuBarConnector we empty and re-instantiate the components of MenuBar. When we are modifying the Menubar from the BlurEventListener of another component, we ,by this, remove widgets, therefore clickEvent is not fired and the action of the MenuItem is not proceed as a result. (The BlurEvent is fired before the click event in the chain of events. ) To improve the situation, we catch onMouseDown event , which is fired before BlurEvent,by assigning mouseDown flag to true. Then if no click event has yet happened, we delay the execution of update inside `updateFromUIDL` by default 500 ms. Then if click event occurs, it proceeds normally. The time can be increased/decreased using setter. There is no delay, if we are clicking on the MenuBar as usual or no Blur listener is set. This change allows setting descriptions * Remove accidentally committed comment * Don't update the state on the getDelayMs call --- server/src/main/java/com/vaadin/ui/MenuBar.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'server/src') diff --git a/server/src/main/java/com/vaadin/ui/MenuBar.java b/server/src/main/java/com/vaadin/ui/MenuBar.java index 7b2437e772..ce43802cc5 100644 --- a/server/src/main/java/com/vaadin/ui/MenuBar.java +++ b/server/src/main/java/com/vaadin/ui/MenuBar.java @@ -450,6 +450,28 @@ public class MenuBar extends AbstractComponent getState().tabIndex = tabIndex; } + /** + * Returns the delay before executing update logic inside + * {@link com.vaadin.client.ui.menubar.MenuBarConnector#updateFromUIDL(UIDL, ApplicationConnection)} + * after mouseDownEvent + * + * @since + */ + public int getDelayMs() { + return getState(false).delayMs; + } + + /** + * Set the delay before executing update logic inside + * {@link com.vaadin.client.ui.menubar.MenuBarConnector#updateFromUIDL(UIDL, ApplicationConnection)} + * after mouseDownEvent + * + * @since + */ + public void setDelayMs(int delayMs) { + getState().delayMs = delayMs; + } + @Override public void focus() { // Overridden only to make public -- cgit v1.2.3