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

Closing issue when using powerselect inside a dialog #117

Open
aatauil opened this issue Dec 10, 2021 · 3 comments
Open

Closing issue when using powerselect inside a dialog #117

aatauil opened this issue Dec 10, 2021 · 3 comments

Comments

@aatauil
Copy link

aatauil commented Dec 10, 2021

When using ember-power-select inside the dialog, the dialog will trigger the @onclose event whenever clicking on the dropdown of the power select. The dropdown of the power-select gets rendered inside the 'ember-basic-dropdown-wormhole' div that is right under the body tag.

I tried to dig into it a bit and found out that it is caused by the headlessui-focus-trap modifier. Specifically allowOutsideClick that always calls the this.onClose(). I am rather unsure why this is the case for a dialog component as I am guessing that notification toasts for example will probably also close the dialog unless if it is rendered inside the <Dialog />'component.

{{headlessui-focus-trap
focusTrapOptions=(hash
initialFocus=@initialFocus
allowOutsideClick=this.allowOutsideClick
setReturnFocus=this.setReturnFocus
)
}}

@action
allowOutsideClick(e: MouseEvent) {
let target = e.target as HTMLElement;
if (target && target.tagName !== 'BODY') {
this.outsideClickedElement = target;
}
this.onClose();
return true;
}

@aatauil
Copy link
Author

aatauil commented Dec 14, 2021

FYI, if anyone else encounters this issue, you can just add the renderInPlace property and set it to true and that will solve the issue for power-select

  <PowerSelect
    @renderInPlace={{true}}
    @options={{this.options}}
    @selected={{this.selected}}
    @onChange={{fn (mut this.selected)}} as |item|>
    {{item.name}}
  </PowerSelect>

@far-fetched
Copy link
Contributor

And you can try to refactor it and use either litsbox or menu component ;)

@aatauil
Copy link
Author

aatauil commented Dec 14, 2021

And you can try to refactor it and use either litsbox or menu component ;)

Yeah for simple dropdown use, absolutely! but went for power-select since I want to take advantage of the search function + multi-select without having to implement it myself :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants