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

ember-rl-dropdown

v0.10.2

Published

Dropdown component and mixin for Ember.js

Downloads

9,047

Readme

Ember-rl-dropdown

Simple dropdown component and mixin for Ember. While it is very straightforward to create toggle functionality in Ember with the if-helper, this dropdown will also close on click-out or when pressing the Escape key.

Build Status

Demo

Demo available here.

Installation

npm install --save-dev ember-rl-dropdown

This addon does not provide any css for the dropdown, but it should work well with frameworks such as Twitter Bootstrap (see example below).

Usage

<!-- Twitter Bootstrap dropdown menu example -->

{{#rl-dropdown-container class="dropdown"}}
  {{#rl-dropdown-toggle class="btn btn-default"}}
    Toggle <span class="caret"></span>
  {{/rl-dropdown-toggle}}

  {{#rl-dropdown tagName="ul" class="dropdown-menu" closeOnChildClick="a:link"}}
    <li><a href="#">Link 1</a></li>
    <li><a href="#">Link 2</a></li>
    <li><a href="#">Link 3</a></li>
  {{/rl-dropdown}}
{{/rl-dropdown-container}}

The component tagnames and classes can be altered to work with your favorite framework or your own custom css.

closeOnChildClick may be set to a jQuery selector for child elements that should cause the dropdown to close when clicked. The default behavior is for the dropdown to remain visible when the user interacts with its child elements. Set it to true if any child element should close the dropdown.

propagateClicks may be set to false on the rl-dropdown-toggle component and/or the rl-dropdown component if click events should not propagate up through the DOM from either or both of these components.

The rl-dropdown-container component also passes a boolean block param indicating whether or not the dropdown is expanded, which can be used to e.g. customize the toggle button text based on whether the dropdown is expanded or closed:

{{#rl-dropdown-container as |dropdownExpanded|}}
  {{#rl-dropdown-toggle}}
    {{#if dropdownExpanded}}
      Close
    {{else}}
      Expand
    {{/if}}
  {{/rl-dropdown-toggle}}

  {{#rl-dropdown}}
    ...
  {{/rl-dropdown}}
{{/rl-dropdown-container}}

It is also possible to bind actions to the onOpen and onClose attributes on the rl-dropdown-container component:

{{#rl-dropdown-container onOpen=(action "myOnOpenHandler") onClose=(action "myOnCloseHandler")}}
  ...
{{/rl-dropdown-container}}

The onOpen action will be called when the dropdown is opened; the onClose action will be called when the dropdown is closed.

Mixin

When integrating dropdown functionality in your own components, you may prefer to use the mixin instead of using the dropdown components. Be sure to add the rl-dropdown-toggle class to your dropdown toggle element, and to add the rl-dropdown class to your dropdown element. You can send toggleDropdown, closeDropdown and openDropdown events to toggle, close or open the dropdown.

// app/components/user-controls.js
import Ember from 'ember';
import DropdownComponentMixin from 'ember-rl-dropdown/mixins/rl-dropdown-component';

export default Ember.Component.extend(DropdownComponentMixin, {
  // Some additional custom behaviour
});
<!-- app/templates/components/user-controls.hbs -->

<!-- Be sure to add the rl-dropdown-toggle class to your dropdown toggle element -->
<button class="rl-dropdown-toggle" {{action "toggleDropdown"}}>User controls</button>

{{#if dropdownExpanded}}
  <!-- Be sure to add the rl-dropdown class to your dropdown element -->
  <div class="user-controls-dropdown rl-dropdown">
    ...
    <a class="close-btn" {{action "closeDropdown"}}>Close</a>
  </div>
{{/if}}