npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@material-git/menu

v2.0.0-git.20160919

Published

Angular 2 Material menu

Downloads

1

Readme

md-menu

md-menu is a list of options that displays when triggered. You can read more about menus in the Material Design spec.

Not yet implemented

  • prevent-close option, to turn off automatic menu close when clicking outside the menu
  • Custom offset support
  • Menu groupings (which menus are allowed to open together)

Usage

Setup

Import the MdMenu module.

my-app-module.ts

import {MdMenuModule} from '@material-git/menu';

@NgModule({
  imports: [MdMenuModule],
  ...
})
export class MyAppModule {}

For alpha.7, you need to include the overlay styles in your app via a link element. This will look something like

<link href="vendor/@material-git/core/overlay/overlay.css" rel="stylesheet">

Simple menu

In your template, create an md-menu element. You can use either <button> or <anchor> tags for your menu items, as long as each is tagged with an md-menu-item attribute. Note that you can disable items by adding the disabled boolean attribute or binding to it.

my-comp.html

<!-- this menu starts as hidden by default -->
<md-menu>
    <button md-menu-item> Refresh </button>
    <button md-menu-item> Settings </button>
    <button md-menu-item> Help </button>
    <button md-menu-item disabled> Sign Out </button>
</md-menu>

Menus are hidden by default, so you'll want to connect up a menu trigger that can open your menu.
You can do so by adding a button tag with an md-menu-trigger-for attribute and passing in the menu instance. You can create a local reference to your menu instance by adding #menu="mdMenu" to
your menu element.

my-comp.html

<!-- menu opens when trigger button is clicked -->
<button md-icon-button [md-menu-trigger-for]="menu">
   <md-icon>more_vert</md-icon>
</button>

<md-menu #menu="mdMenu">
    <button md-menu-item> Refresh </button>
    <button md-menu-item> Settings </button>
    <button md-menu-item> Help </button>
    <button md-menu-item disabled> Sign Out </button>
</md-menu>

Output:

Toggling the menu programmatically

You can also use the menu's API to open or close the menu programmatically from your class. Please note that in this case, an md-menu-trigger-for attribute is still necessary to connect the menu to its trigger element in the DOM.

my-comp.component.ts

class MyComp {
  @ViewChild(MdMenuTrigger) trigger: MdMenuTrigger;

  someMethod() {
    this.trigger.openMenu();
  }
}

my-comp.html

<button md-icon-button [md-menu-trigger-for]="menu">
   <md-icon>more_vert</md-icon>
</button>

<md-menu #menu="mdMenu">
    <button md-menu-item> Refresh </button>
    <button md-menu-item> Settings </button>
    <button md-menu-item> Help </button>
    <button md-menu-item disabled> Sign Out </button>
</md-menu>

Customizing menu position

By default, the menu will display after and below its trigger. You can change this display position using the x-position (before | after) and y-position (above | below) attributes.

my-comp.html

<md-menu x-position="before" #menu="mdMenu">
    <button md-menu-item> Refresh </button>
    <button md-menu-item> Settings </button>
    <button md-menu-item> Help </button>
    <button md-menu-item disabled> Sign Out </button>
</md-menu>

Output:

Accessibility

The menu adds role="menu" to the main menu element and role="menuitem" to each menu item. It also adds aria-hasPopup="true" to the trigger element.

Keyboard events:

  • DOWN_ARROW: Focus next menu item
  • UP_ARROW: Focus previous menu item
  • ENTER: Select focused item

Menu attributes

| Signature | Values | Description | | --- | --- | --- | | x-position | before | after | The horizontal position of the menu in relation to the trigger. Defaults to after. | | y-position | above | below | The vertical position of the menu in relation to the trigger. Defaults to below. |

Trigger Programmatic API

Properties

| Name | Type | Description | | --- | --- | --- | | menuOpen | Boolean | Property that is true when the menu is open. It is not settable (use methods below). | | onMenuOpen | Observable<void> | Observable that emits when the menu opens. | | onMenuClose | Observable<void> | Observable that emits when the menu closes. |

Methods

| Method | Returns | Description | | --- | --- | --- | | openMenu() | Promise<void> | Opens the menu. Returns a promise that will resolve when the menu has opened. | | closeMenu() | Promise<void> | Closes the menu. Returns a promise that will resolve when the menu has closed. | | toggleMenu() | Promise<void> | Toggles the menu. Returns a promise that will resolve when the menu has completed opening or closing. |
| destroyMenu() | Promise<void> | Destroys the menu overlay completely.