Skip to content

Commit

Permalink
fix(dropdowns): dropdown should close correctly when used in modals (f…
Browse files Browse the repository at this point in the history
…ixes #267, fixes #221)
  • Loading branch information
mkjeff committed Mar 25, 2016
1 parent 898722a commit a7a02ff
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions components/dropdown/dropdown.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class Dropdown implements OnInit, OnDestroy {
@Output() public isOpenChange:EventEmitter<boolean> = new EventEmitter();
@HostBinding('class.dropdown') private addClass = true;


private _isOpen:boolean;
// index of selected element
public selectedOption:number;
Expand Down
7 changes: 3 additions & 4 deletions components/dropdown/dropdown.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ import {Dropdown} from './dropdown.directive';

export class DropdownService {
private openScope:Dropdown;
private dropdownScope:Dropdown;

private closeDropdownBind:EventListener = this.closeDropdown.bind(this);
private keybindFilterBind:EventListener = this.keybindFilter.bind(this);

public open(dropdownScope:Dropdown) {
if (!this.openScope) {
window.document.addEventListener('click', this.closeDropdownBind);
window.document.addEventListener('click', this.closeDropdownBind, true);
window.document.addEventListener('keydown', this.keybindFilterBind);
}

if (this.openScope && this.openScope !== this.dropdownScope) {
if (this.openScope && this.openScope !== dropdownScope) {
this.openScope.isOpen = false;
}

Expand All @@ -31,7 +30,7 @@ export class DropdownService {
}

this.openScope = null;
window.document.removeEventListener('click', this.closeDropdownBind);
window.document.removeEventListener('click', this.closeDropdownBind, true);
window.document.removeEventListener('keydown', this.keybindFilterBind);
}

Expand Down

0 comments on commit a7a02ff

Please sign in to comment.