Skip to content

Instantly share code, notes, and snippets.

@soulcutter
Created November 25, 2014 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save soulcutter/ef377becfc8b381f92c9 to your computer and use it in GitHub Desktop.
Save soulcutter/ef377becfc8b381f92c9 to your computer and use it in GitHub Desktop.
Dropdown ember component
<button class="navDropdown__button" {{action "toggleNavigationDropdown" target="view"}}>{{view.title}}</button>
{{yield}}
import Ember from "ember";
export default Ember.Component.extend({
tagName: 'nav',
classNames: ['navDropdown'],
classNameBindings: ['isDropdownVisible:is--open'],
ariaRole: 'navigation',
isDropdownVisible: false,
actions: {
toggleNavigationDropdown: function() {
this.toggleProperty('isDropdownVisible');
}
},
attachClickHandler: function() {
var component = this;
Ember.$(window).on("click." + component.elementId, function(e) {
if(!Ember.$.contains(component.element, e.target)) {
component.set('isDropdownVisible', false);
}
return true;
});
}.on('didInsertElement'),
detachClickHandler: function() {
Ember.$(window).off("click." + this.elementId);
}.on('willDestroyElement'),
});
@soulcutter
Copy link
Author

{{#dropdown-menu title="More…"}}
  <div>initially-hidden contents of dropdown here</div>
{{/dropdown-menu}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment