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

SetupDragIn not working inside the web component #2275

Closed
arulselvan opened this issue Apr 23, 2023 · 7 comments · Fixed by #2287 or #2305
Closed

SetupDragIn not working inside the web component #2275

arulselvan opened this issue Apr 23, 2023 · 7 comments · Fixed by #2287 or #2305

Comments

@arulselvan
Copy link

GridStack.setupDragIn not working inside the web component

Tried Gridstack inside the Lit web component, and it's working fine, but the scenario like dragging in the element from the sidebar (https://gridstackjs.com/demo/static.html) does not work inside shadow root.

Environment

  • version of gridstack.js - ^7.2.3

  • which browser/OS - all

Steps to reproduce

GridStack.setupDragIn method need to be called inside the web component(ShadowRoot), The following link has a working demo to reproduce the same inside Lit.
https://stackblitz.com/edit/vitest-dev-vitest-bzx77k?file=src/designer.ts

Expected behavior

Currently, inside setupDragInMethod, we are calling Utils.getElements,

Utils.getElements(dragIn).forEach(el => {

Utils.getElements internally using document.querySelectorAll, I think to work inside the shadow root, we need to query inside the parent element or give an argument to the method where we should look in the shadow root scenario...

let list = document.querySelectorAll(els);

@adumesny
Copy link
Member

or we could make setupDragIn() take an array of elements | string selector (like other methods) and you can pass the items you need... that may be more flexible in the long run.

adumesny added a commit to adumesny/gridstack.js that referenced this issue Apr 29, 2023
* fix gridstack#2275
* `setupDragIn()` now can take an array or elements (in addition to selector string) and optional parent root (for shadow DOM support)
@adumesny
Copy link
Member

adumesny commented Apr 29, 2023

I didn't get to test it, but this should handle it in the next release.

@arulselvan
Copy link
Author

I didn't get to test it, but this should handle it in the next release.

thanks @adumesny! upgraded to V8.0.1, and tested, works like a charm :)

@adumesny
Copy link
Member

adumesny commented May 3, 2023

curious, are you passing a list of elements or the virtual DOM parent ?

@arulselvan
Copy link
Author

arulselvan commented May 5, 2023

tested both, and I'm passing a list of elements like the below snip...

`const availableWidgets = this.querySelectorAll(".newWidget");

const widgetElements: HTMLElement[] = Array.from(
  availableWidgets
) as HTMLElement[];

GridStack.setupDragIn(widgetElements, {
  appendTo: "parent",
  helper: "clone",
});`

Just thought, for Passing the root element as a param I think we can define a better type instead of the Document type currently tested the below snip works fine, but found during debugging inside Util.getElement in some specific condition, we using root.getElementById that might not be available for HTMLElement...

const root: Document = this.querySelector("#widgets-container") as unknown as Document; GridStack.setupDragIn(".newWidget", { appendTo: "parent", helper: "clone" }, root);

@adumesny
Copy link
Member

adumesny commented May 5, 2023

good point. Utils.getElements() is supposed to get all elements (by class selector) but is also called for single ID which only works on the document, so signature need to be HTMLElement | Document. I'll change that.

@adumesny adumesny reopened this May 5, 2023
adumesny added a commit to adumesny/gridstack.js that referenced this issue May 6, 2023
* set root: HTMLElement | Document so either can be passed now
more fix gridstack#2275
@adumesny
Copy link
Member

adumesny commented May 6, 2023

fixed the types. don't forget to donate if you find this lib useful!

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