Preventing MenuBar from closing when MenuBarRootItem is clicked.

I have a simple MenuBar like :

MenuBar menu = new MenuBar(); menu.addItem(VaadinIcon.PLUS.create(), event -> increase()); menu.addItem(VaadinIcon.MINUS.create(), event -> decrease());

I would like to modify the default behavior of MenuBar so that it doesn’t close when I click on the items (to be able to click them several times). Can someone tell me how to achieve this please ?

I had it to work thanks to this post :
The trick was to write a KeepMenuBarOpenDecorator class :

public class KeepMenuBarOpenDecorator {

    public KeepMenuBarOpenDecorator(MenuItem menuItem) {
        menuItem.getElement().addEventListener("click", e -> {

    public static void keepOpenOnClick(MenuItem menuItem) {
        new KeepMenuBarOpenDecorator(menuItem);

    public static void keepOpenOnClick(SubMenu subMenu) {

And decorate the menu items with :

MenuBar menu = new MenuBar();
KeepMenuBarOpenDecorator.keepOpenOnClick(menu.addItem(VaadinIcon.PLUS.create(), event -> increase()));
KeepMenuBarOpenDecorator.keepOpenOnClick(menu.addItem(VaadinIcon.MINUS.create(), event -> decrease()));

Now the menu bar wont close when clicking on items.
Hope it helps.