Class VerticalMenu

java.lang.Object
com.vaadin.flow.component.Component
com.flowingcode.vaadin.addons.verticalmenu.VerticalMenu
All Implemented Interfaces:
AttachNotifier, DetachNotifier, HasElement, HasSize, Serializable

@Tag("div") @StyleSheet("context://frontend/styles/vertical-menu-styles.css") @JavaScript("./scripts/vertical-menu-styles.js") public class VerticalMenu extends Component implements HasSize
Vaadin component that represents a vertical menu with sections. How to use this component:
  1. Create your sections. Sections are created using the class Section.
  2. Create the items of your sections. To add items to a section, simply call new Section(...) and pass the section content as arguments.
  3. Create an instance of this component. To create an instance, call new VerticalMenu(...) and pass your sections as arguments. Note: you can also add or remove sections later using the methods getSections() and setSections(List).
  4. Add the component to your layout.
  5. Listen for menu selected events. You can listen for menu selected events by adding a VerticalMenu.MenuSelectedEvent listener to the component instance. To add a listener use the method addMenuSelectedListener(ComponentEventListener).
Author:
Martin Lopez / Flowing Code
See Also:
  • Constructor Details

    • VerticalMenu

      public VerticalMenu(Section... sections)
      Creates an instance of VerticalMenu with the provided sections. When the menu is created, it sets its initial size, appends a title, adds a menu button, and loads the sections that were passed as arguments.
      Parameters:
      sections - The initial sections to display. These sections can be added or removed later using the method setSections(List)
  • Method Details

    • reloadSections

      public void reloadSections()
      Reloads all the sections from getSections().
    • onAttach

      protected void onAttach(AttachEvent attachEvent)
      Attaches the component to the view. When the component is attached to a UI view, it appends a style tag to the document's head with the specified classes. A vertical-menu CSS class is added to the document head.
      Overrides:
      onAttach in class Component
    • onDetach

      protected void onDetach(DetachEvent detachEvent)
      Detaches the component from the view. When the component is detached, the added styles will also be removed.
      Overrides:
      onDetach in class Component
    • addMenuSelectedListener

      public Registration addMenuSelectedListener(ComponentEventListener<VerticalMenu.MenuSelectedEvent> listener)
      Adds a new MenuSelectedEvent listener to the component.
      Parameters:
      listener - The new MenuSelectedEvent listener
      Returns:
      A registration object from the listener that can be used later to remove the listener
    • getSections

      public List<Section> getSections()
      Returns the current list of sections in the component.
      Returns:
      The current list of sections in the component
    • setSections

      public void setSections(List<Section> sections)
      Sets the new list of sections to display on the component. All changes are immediately updated on this instance and its view. Also, it reloads all sections, effectively repainting the component.
      Parameters:
      sections - The new list of sections