2.5.6 • Published 1 month ago

@dreamworld/dw-menu v2.5.6

Weekly downloads
-
License
ISC
Repository
github
Last release
1 month ago

<dw-menu> Published on npm

  • Menus displays a list of choices on temporary surfaces like Popover dialog in Desktop and Tablet.
  • On mobile, the Menu is displayed on the bottom sheet. When menu items are overflowed Menu items are shown as Fit Dialog.
  • Menu is composed of various menu items.
  • It may have Divider to group menu items.

Note: dw-menu extends dw-composite-dialog to render a temporary surface. So, dw-menu has all the behaviors of dw-composite-dialog.

Installation

npm install @dreamworld/dw-menu

Example usage

Default

<dw-menu .actions="${actions}" .disabledActions="${disabledActions}" .hiddenActions="${hiddenActions}" @action="${handler}"></dw-menu>

Mobile Mode

<dw-menu
  mobile-mode
  .heading="${'Heading'}"
  .actions="${actions}"
  .disabledActions="${disabledActions}"
  .hiddenActions="${hiddenActions}"
  @action="${handler}"
></dw-menu>

API

Properties/Attributes

NameTypeDefaultDescription
openedbooleanfalseSet to true to show it opened.
actionsAction[]undefinedRepresent total available actions/sub actions in the menu.
disabledActionsObjectundefinedSpecifies actions that are disabled. key = action name, value = Tooltip message to be shown for that action.
hiddenActionsString[][]Actions specified here aren't visible (rendered) in the menu.
mobileModebooleanfalseDisplayed on the bottom sheet in most cases. When menu items are overflowed Menu items are shown as Fit dialog.
anchorHTMLElement|nullnullElement to which this menu should be anchored. Applicable only when mobileMode=false.
keepAnchorVisiblebooleanfalseBy default, When the menu is opened, it covers (hides) the anchor elements. Set it to true, to make it visible. Applicable only when mobileMode=false.
placementStringtop-startPossible values: top-start, top-end, bottom-start and bottom-end. Applicable only when mobileMode=false.
headingStringnullSet it if you would like to show a heading on the menu. By default no heading.
showClosebooleanfalseShows an icon-button with a close icon, in the top-right corner. As the menu is closed when the user clicks away, this isn't needed in most cases. Though, if you would like to show it sometimes, e.g. when mobileMode=true.
disableAutoCloseBooleanfalseTo prevent the close event from triggering on menu item clicks, it has been disabled. The close event will now be dispatched exclusively when the close icon is clicked, when a user clicks outside the menu, or when the menu is closed through any other appropriate means.

Action

Object

KeyTypeDescription
nameStringname of the action. It's available in action event detail.
labelStringlabel of the action
iconStringName of the icon to show as a leading icon
dangerBooleanShows action in danger mode. e.g. For delete action, you might need it.
typeStringType of the action. Applicable only when action has subActions. possible values: collapsible, submenu. default value: collapsible
subActionsArray[]Sub Actions of the current action. Used when a group of actions comes under any same parent item.
dividerBooleanSet border bottom of the list item.
hasLeadingIconSpaceBooleanLeave space for the icon (40px) in the list item. only applicable when an icon value has not been set.

Example

Basic
{
  name: "ADD",
  label: "Add",
  icon: "add",
}
With Sub Actions
{
  name: "ADD",
  label: "Add",
  icon: "add",
  subActions: [
    {name: "TOP", label: "Move to Top", icon: 'arrow_up'},
    {name: "BOTTOM", label: "Move to Bottom", icon: 'arrow_down'}
  ]
}
Danger action
{
  name: "DELETE",
  label: "Delete",
  icon: "delete",
  danger: true
}

Sub Actions Without Leading Icon

[{ name: "ADD", label: "Add", icon: "add", subActions: {name: "TOP", label: "Move to Top", hasLeadingIconSpace: true}, {name: "BOTTOM", label: "Move to Bottom", hasLeadingIconSpace: true} }, { name: "ADD", label: "Add", hasLeadingIconSpace: true subActions: {name: "TOP", label: "Move to Top", hasLeadingIconSpace: true}, {name: "BOTTOM", label: "Move to Bottom", hasLeadingIconSpace: true} }]

disabledActions

  • Specifies actions that are disabled.
  • key = action name
  • value = text (Tooltip message to be shown for that action) OR true (disable an item but don't want to show any tip).
  • NOTE: These actions must be declared in the actions property.
{
  SHARE: "Share is disabled"
  DELETE: true
}

Events

Event NameTargetDetailDescription
actiondw-menu{name}Fired when a menu item is selected by the User (keyboard or mouse interaction). name represents the action represented by the selected menu item.

CSS Custom Properties

NameDefaultDescription
--dw-menu-header-padding0 0 0 16pxPadding of header area.
--dw-menu-content-padding0Padding of content area.
--dw-menu-danger-action-color#B00020Danger action color
--dw-menu-list-item-divider-colorrgba(0, 0, 0, 0.12)Divider color for collapsible list item

Design Decisions

  • No property to configure animation. Animation style would be as suggested by the material standards.

Future Enhancements

  • Keyboard Navigation
  • Custom Footer (via slot or template override)
  • Group Items (divider)
  • Tooltip for the Disabled Items.
  • Expandable Menu Items
  • href (Link) support for an Item. It may be set to open in a new window only. In that case, it’s trailing icon is also auto-chosen.
  • Sub-Menu: Opens another menu on the side of the current menu. (Long-term deferred)
2.5.6

1 month ago

2.4.2

10 months ago

2.5.5

7 months ago

2.5.0

10 months ago

2.5.2

9 months ago

2.5.1

9 months ago

2.5.4

8 months ago

2.5.3

9 months ago

2.5.2-trigger.1

9 months ago

2.4.1

12 months ago

2.4.0

1 year ago

2.3.1

1 year ago

2.3.0

1 year ago

2.2.0

1 year ago

2.1.0

1 year ago

2.0.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago