Skip to content

Commit

Permalink
Merge pull request #280 from mkjeff/master
Browse files Browse the repository at this point in the history
fix(dropdowns): dropdown should close correctly when used in modals (fixes #267, fixes #221)
  • Loading branch information
valorkin committed Mar 25, 2016
2 parents f7a857c + a7a02ff commit 6c1358e
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 6c1358e

Please sign in to comment.