Socket
Socket
Sign inDemoInstall

@github/details-menu-element

Package Overview
Dependencies
Maintainers
14
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@github/details-menu-element

A menu opened with a <details> button.


Version published
Weekly downloads
33K
decreased by-8.47%
Maintainers
14
Weekly downloads
 
Created
Source

<details-menu> element

A menu that's opened with a <details> button.

Installation

$ npm install @github/details-menu-element

Usage

import '@github/details-menu-element'
<details>
  <summary>Robots</summary>
  <details-menu>
    <ul>
      <li><button type="button" role="menuitem">Hubot</button></li>
      <li><button type="button" role="menuitem">Bender</button></li>
      <li><button type="button" role="menuitem">BB-8</button></li>
    </ul>
  </details-menu>
</details>

Use data-menu-button and data-menu-button-text to have button text updated on menu item activation.

<details>
  <summary>Preferred robot: <span data-menu-button>None</span></summary>
  <details-menu>
    <ul>
      <li><button type="button" role="menuitem" data-menu-button-text>Hubot</button></li>
      <li><button type="button" role="menuitem" data-menu-button-text>Bender</button></li>
      <li><button type="button" role="menuitem" data-menu-button-text>BB-8</button></li>
    </ul>
  </details-menu>
</details>

Use label[tabindex="0"][role=menuitemradio/menuitemcheckbox] when dealing with radio and checkbox inputs menu items. Check states of the input element and the label will be synchronized.

<details>
  <summary>Preferred robot</summary>
  <details-menu>
    <ul>
      <li><label tabindex="0" role="menuitemradio">
        <input type="radio" name="robot" value="Hubot"> Hubot
      </label></li>
      <li><label tabindex="0" role="menuitemradio">
        <input type="radio" name="robot" value="Bender"> Bender
      </label></li>
      <li><label tabindex="0" role="menuitemradio">
        <input type="radio" name="robot" value="BB-8"> BB-8
      </label></li>
    </ul>
  </details-menu>
</details>

Events

  • details-menu-select - An item is to be select (cancelable).
  • details-menu-selected - An item is selected, label updated, menu closed.

Deferred loading

Menu content can be loaded from a server by embedding an <include-fragment> element.

<details>
  <summary>Robots</summary>
  <details-menu src="/robots" preload>
    <include-fragment>Loading…</include-fragment>
  </details-menu>
</details>

The src attribute value is copied to the <include-fragment> the first time the <details> button is toggled open, which starts the server fetch.

If the preload attribute is present, the server fetch will begin on mouse hover over the <details> button, so the content may be loaded by the time the menu is opened.

Browser support

Browsers without native custom element support require a polyfill.

  • Chrome
  • Firefox
  • Safari
  • Internet Explorer 11
  • Microsoft Edge

Development

npm install
npm test

License

Distributed under the MIT license. See LICENSE for details.

Keywords

FAQs

Package last updated on 31 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc