MenuBar stay select/focus

Hello, is possible after select item menubar to stay select/focus this menu item?

Another question: I use vaadin navigation, navigateTo(address) how can I select this MenuBar menuItem, where i navigate ?

Hi,

The MenuBar doesn’t have built-in support for indicating the last selection. You can indicate the last selection easily using either the “checked” property or a CSS style name (just don’t use the obvious “selected” style name, as it is an internal reserved name in the component).

MenuBar barmenu = new MenuBar();
barmenu.addStyleName("mybarmenu");
layout.addComponent(barmenu);
        
// A feedback component
final Label selection = new Label("-");
layout.addComponent(selection);

// Define a common menu command for all the menu items.
MenuBar.Command mycommand = new MenuBar.Command() {
    MenuItem previous = null;

    public void menuSelected(MenuItem selectedItem) {
        selection.setValue("Ordered a " +
                selectedItem.getText() +
                " from menu.");

        if (previous != null)
            previous.setChecked(false);
        selectedItem.setCheckable(true);
        selectedItem.setChecked(true);
        previous = selectedItem;
    }  
};
        
// Put some items in the menu
barmenu.addItem("Beverages", null, mycommand);
barmenu.addItem("Snacks", null, mycommand);
barmenu.addItem("Services", null, mycommand);

And in the theme:

.mybarmenu .v-menubar-menuitem-checked {
    background: #000040; /* Dark blue */
}

…as shown
here
.