Skip to content

Commit

Permalink
fix: "outsideClick" still closed the dropdown on any click
Browse files Browse the repository at this point in the history
- Implement a `DropdownMenu` directive to fix "always undefined directive.menuEl"
- Test for "OUTSIDECLICK" should not consider menu children to be outside the menu

This fixes #124
  • Loading branch information
rluba committed Feb 10, 2016
1 parent eec3cb4 commit 6348f72
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion components/dropdown.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {Dropdown} from './dropdown/dropdown.directive';
import {DropdownMenu} from './dropdown/dropdown-menu.directive';
import {DropdownToggle} from './dropdown/dropdown-toggle.directive';

export {Dropdown} from './dropdown/dropdown.directive';
export {DropdownMenu} from './dropdown/dropdown-menu.directive';
export {DropdownToggle} from './dropdown/dropdown-toggle.directive';
export const DROPDOWN_DIRECTIVES: Array<any> = [Dropdown, DropdownToggle];
export const DROPDOWN_DIRECTIVES: Array<any> = [Dropdown, DropdownToggle, DropdownMenu];
16 changes: 16 additions & 0 deletions components/dropdown/dropdown-menu.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {
Directive, ElementRef, Host,
OnInit
} from 'angular2/core';

import {Dropdown} from './dropdown.directive';

@Directive({ selector: '[dropdownMenu]' })
export class DropdownMenu implements OnInit {
constructor( @Host() public dropdown: Dropdown, public el: ElementRef) {
}

public ngOnInit() {
this.dropdown.dropDownMenu = this;
}
}
2 changes: 1 addition & 1 deletion components/dropdown/dropdown.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class DropdownService {

if (event && this.openScope.autoClose === OUTSIDECLICK &&
this.openScope.menuEl &&
this.openScope.menuEl.nativeElement === event.target) {
this.openScope.menuEl.nativeElement.contains(event.target)) {
return;
}

Expand Down

0 comments on commit 6348f72

Please sign in to comment.