This is a component for generating flexible, nestable menus. It can generates nested menus from a flat list with node id
s and parentId
s.
Install with:
meteor add utilities:menu
Then just include the menuComponent
template while passing the necessary arguments:
{{> menuComponent menuItems=menuItems menuLabel="My Menu" menuClass="my-menu-class"}}
All arguments are optional unless specified otherwise.
One of list
, dropdown
, or collapsible
. Defaults to list
.
An array containing the menu's contents (see below).
The name of the menu. Used to set a *name*-menu
CSS class on the menu.
The menu title label, or a function that returns a label. Note that this is required for dropdown menus.
If provided, will replace the menu label with a custom template.
An optional CSS class given to the menu
A custom template used to display individual menu items (defaults to "defaultMenuItem")
For collapsible menus only, how far to open the menu. 0
means the menu contents are collapsed, 1
expands the first level, 2
expands up to the second level, etc., and all
expands the entire menu. Defaults to 1
.
Menu items can have the following properties:
The menu item's label, or a function that returns a label.
The menu item's description, or a function that returns a description.
Either the name of a route to which the menu item should point, or a function that returns a route.
If a route is provided, the class item-active
will automatically be added to the menu item when its route is the currently active one.
The data context for the item.
The menu item's CSS class.
An optional custom template. Overrides both the default template and the itemTemplate
menu-level option.
Additionally, menu items take a few additional properties to generate nested menus.
A unique id used for arranging nodes in nested menus.
The parent node's id.
Whether the item's sub-menu should start off expanded
The menu item template is called with the following data context:
A reference pointing back to the menu object.
The current nesting level.
The current item to display.
Out of the box, the menu component accepts a few classes
A simple list. Serves as the base for the other styles.
A dropdown menu.
A collapsible menu.
The menu component includes a few events. Classes used for JS event targeting start with the js-
prefix.
Makes the current node's child menu expand and collapse.