Automatic menu with hierarcy support in Viritin 2.10.1

Viritin add-on has for a long time had a class called MainLayot, which builds a top level navigation for the app based on the available routes. @MenuItem annotation has been available to override things like text and the icon. During the years implementation has changed to utilise the AppLayout and SideNav components that are nowadays shipped with the core. Now just recently, I ticked a long standing TODO to implement some sort of support for hierarchical menus. Finally, it was rather simple as the SideNav also has gained support for hierarchical items.

One can now pass parent parameter for the MenuItem annotation and the menu structure becomes hierarchical. If the parent extends Component, it is considered to be an actual view as well. Else it is “just a label”. The MenuItem annotation has flags to control if the submenu is collapsible and its initial state.

In the same iteration, I added a support for the new Menu annotation introduced in the Vaadin 24.5. MainLayout respects those configurations as well, but these don’t include configurations for the menu hierarchy.

Online demo

3 Likes