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

Sl-dropdown is broken when removed and appended back to DOM #443

Closed
ex37 opened this issue May 25, 2021 · 2 comments
Closed

Sl-dropdown is broken when removed and appended back to DOM #443

ex37 opened this issue May 25, 2021 · 2 comments
Assignees
Labels
bug Things that aren't working right in the library.

Comments

@ex37
Copy link

ex37 commented May 25, 2021

Describe the bug

In dropdown component, this.popover is initialized in firstUpdated hook, but is destroyed in disconnectedCallback , thus when removing the dropdown from DOM and then appending again the popover is broken.

To Reproduce

  1. Create a sl-dropdown
  2. Programmatically remove it from DOM
  3. Append back to DOM
  4. Open and then close the dropwdown, it's remaining open, cause this.popover.hide() can't be called (this.popover is destroyed)

Expected behavior
Dropdown should keep working as intended when programmatically moving within DOM.

@ex37 ex37 added the bug Things that aren't working right in the library. label May 25, 2021
@claviska
Copy link
Member

Thanks for reporting this. I was able to replicate the issue and fixed it in d7bf0bd.

@ex37
Copy link
Author

ex37 commented May 26, 2021

Hi @claviska thanks for fast response!
I spent some time and reviewed other occurrences where firstUpdated is used, and just by looking at the code (haven't tried to reproduce any of these), here is what I found:

https://github.com/shoelace-style/shoelace/blob/next/src/components/icon-button/icon-button.ts#L41

focusVisible.observe(this.button); should be moved to connectedCallback

https://github.com/shoelace-style/shoelace/blob/next/src/components/rating/rating.ts#L66
https://github.com/shoelace-style/shoelace/blob/next/src/components/details/details.ts#L68

exactly same issue

https://github.com/shoelace-style/shoelace/blob/next/src/components/tooltip/tooltip.ts#L103

this.popover = new Popover(this.target, this.positioner); should be moved to connectedCallback,
as well as all of the event listeners. Maybe also this.target = this.getTarget();, not sure about this one, but overall in the current state I find tooltip component not enought dynamic and ended up wraping it into my own one. If you are interested I can collaborate my thoughts on this component.

https://github.com/shoelace-style/shoelace/blob/next/src/components/textarea/textarea.ts#L141
this.resizeObserver.observe(this.input); should be moved

https://github.com/shoelace-style/shoelace/blob/next/src/components/tab-group/tab-group.ts#L65
this.resizeObserver.observe(this.nav); and the creation of this.mutationObserver should be moved

Hope this helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Things that aren't working right in the library.
Projects
None yet
Development

No branches or pull requests

2 participants