Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dropdown not work on angular2-modal #267

Closed
mkjeff opened this issue Mar 10, 2016 · 2 comments
Closed

Dropdown not work on angular2-modal #267

mkjeff opened this issue Mar 10, 2016 · 2 comments
Assignees
Labels

Comments

@mkjeff
Copy link
Contributor

mkjeff commented Mar 10, 2016

I am using dropdown directive with angular2-modal

found the issue that drop-down menu didn't auto close, because modal component will prevent the click event bubbling up.

so, I think the window not appropriated listenser target(in /components/dropdown/dropdown.service.ts)

window.document.addEventListener('click', this.closeDropdownBind);

is it possible to change that?

@valorkin valorkin modified the milestones: RC, QA Mar 10, 2016
@valorkin valorkin self-assigned this Mar 10, 2016
@valorkin valorkin added the issue label Mar 10, 2016
@valorkin valorkin changed the title Dropdown not work on angular2-modal Dropdown not work on angular2-modal Mar 10, 2016
@mkjeff
Copy link
Contributor Author

mkjeff commented Mar 11, 2016

I did a temporary work around.

add a rootElement to dropdown directive

class Dropdown {
  @Input()
  public rootElement: HTMLElement;
}

and pass it in host template

<div class="modal-root" #modal>
   <div class="btn-group" dropdown [rootElement]="modal" keyboardNav="true">...</div>
</div>

and dropdown.service can binding event listener to it

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

have any better idea?

@mkjeff
Copy link
Contributor Author

mkjeff commented Mar 24, 2016

I found a better way, no need to change directive interface.
Uses the third parameter useCapture(true) on addEventListener/removeEventListener.
commit

valorkin added a commit that referenced this issue Mar 25, 2016
fix(dropdowns): dropdown should close correctly when used in modals (fixes #267, fixes #221)
@valorkin valorkin self-assigned this Mar 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants