Items in my menu do have sub-menu items.
How can I set style for parent when a child is selected?
Currently, I’m trying to use setStyleName in menuSelected function like what I posted below, but it does not work.
public void menuSelected(final MenuItem selectedItem) {
removeAllStyleFromMenuItem();
setHighLightSelectedMenuItem(selectedItem);
}
private void setHighLightSelectedMenuItem(final MenuItem selectedItem) {
if (selectedItem.getParent() == null) {
selectedItem.setStyleName("selected");
} else {
setHighLightSelectedMenuItem(selectedItem.getParent());
}
}
Please give me the feedback if anyone knows any solution.
Thank you in advance.
I see, if you do something like this selectedItem.setStyleName(“selected”); you should have something set for target selected in your styles, otherwise there is no effect. You should have something like this in your styles.
.selected {
background-color: red
}
Although I would give more specific stylename for my custom style in order to avoid conflicts.