new Dropdown(navList, options)
Parameters:
| Name | Type | Description |
|---|---|---|
navList |
Array.<(Dropdown~NavItem|Dropdown~NavMenu|Dropdown~NavDivider)> | Object representation of the context menu. |
options |
Dropdown~Options | Optional parameters for this instance |
Methods
-
dismiss()
-
Close a dropdown and remove all event listeners on it
-
open(left, top [, autoExpandDir] [, context])
-
Open the dropdown rooted in the given position. It will expand down and to the right by default, but change expansion direction if it does not have enough space.
Parameters:
Name Type Argument Default Description leftNumber How many pixels from the left the element should be positioned topNumber How many pixels from the top the element should be positioned autoExpandDirboolean <optional>
true If true we will automatically expand the dropdown towards the top or left if we don't have any space for it below or to the right. If false we will only expand down and to the right. contextany <optional>
Optional context which is set on the Dropdown instance when we open it. This can be anything and is available through this.contexton the action function -
openClick(evt [, context])
-
This function will take an event and try to open and position the dropdown next to the mouse pointer or the element the event triggered on.
Parameters:
Name Type Argument Description evtEvent The event that triggered this click contextany <optional>
Optional context which is set on the Dropdown instance when we open it. This can be anything and is available through this.contexton the action function
Type Definitions
-
actionCallback(event)
-
The action callback. The
thiscontext is the instance of the dropdown itself unless otherwise bound.Parameters:
Name Type Description eventEvent This is the event (either click or keypress) which triggered this handler -
logger(logItems)
-
The logging function. Use this if you want to expose internal logging information.
Parameters:
Name Type Argument Description logItems* <repeatable>
This should work similarly to how console.loguses multiple parameters -
This is the structure of a navigation divider. It is just like the NavItem with no label or action.
Type:
- Object
Properties:
Name Type Argument Description keystring <optional>
A unique key for this item. It will be auto generated if not supplied -
This is the structure of a navigation item
Type:
- Object
Properties:
Name Type Argument Default Description labelstring | function The label which is used in the menu. If it is a function it will be called every time the menu is opened and set the label to the return value of this function. The thisobject of the function is the Dropdown instance itself unless otherwise bound.iconstring <optional>
An icon to be used. This needs to be a path to a valid css background-image string. keystring <optional>
A unique key for this item. It will be auto generated if not supplied disabledboolean <optional>
false If this is true the item is disabled. When disabled we will not navigate according to the action parameter or run the action callback. actionstring | Dropdown~actionCallback What to do when we select this nav item. If this is a string we will navigate like an <a> tag -
This is the structure of a navigation submenu
Type:
- Object
Properties:
Name Type Argument Default Description labelstring The label which is used in the menu iconstring <optional>
An icon to be used. This needs to be a path to a valid css background-image string. keystring <optional>
A unique key for this item. It will be auto generated if not supplied disabledboolean <optional>
false If this is true the item is disabled. When disabled it will not be expanded childrenArray.<(Dropdown~NavItem|Dropdown~NavMenu|Dropdown~NavDivider)> The children of this menu -
Options
-
This is the structure of the options object
Type:
- Object
Properties:
Name Type Argument Default Description loggerDropdown~logger <optional>
console.log The logger to use elementElement <optional>
document.body The element to attach the dropdown to