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:
- Create your sections. Sections are created using the class
Section. - Create the items of your sections. To add items to a section, simply call
new Section(...)and pass the section content as arguments. - 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 methodsgetSections()andsetSections(List). - Add the component to your layout.
- Listen for menu selected events. You can listen for menu selected events by adding a
VerticalMenu.MenuSelectedEventlistener to the component instance. To add a listener use the methodaddMenuSelectedListener(ComponentEventListener).
- Author:
- Martin Lopez / Flowing Code
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionVerticalMenu(Section... sections) Creates an instance of VerticalMenu with the provided sections. -
Method Summary
Modifier and TypeMethodDescriptionAdds a new MenuSelectedEvent listener to the component.Returns the current list of sections in the component.protected voidonAttach(AttachEvent attachEvent) Attaches the component to the view.protected voidonDetach(DetachEvent detachEvent) Detaches the component from the view.voidReloads all the sections fromgetSections().voidsetSections(List<Section> sections) Sets the new list of sections to display on the component.Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, set, setElement, setId, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull
-
Constructor Details
-
VerticalMenu
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 methodsetSections(List)
-
-
Method Details
-
reloadSections
public void reloadSections()Reloads all the sections fromgetSections(). -
onAttach
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. Avertical-menuCSS class is added to the document head. -
onDetach
Detaches the component from the view. When the component is detached, the added styles will also be removed. -
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
Returns the current list of sections in the component.- Returns:
- The current list of sections in the component
-
setSections
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
-