You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
👋🏾 Hello again! After getting around the react-dnd issue I described in #106, I was able to use pdnd to support drag and drop in some feature code here at Slack 🚀 . Overall it was pretty smooth, though I'm reaching out with a request that will help me release the change. The request is to optionally support passing window as a param.
For context, the Slack desktop client supports multiple windows. Drag and drop works great in our "main" window, though it doesn't work if you open a view in a separate "child" window. We manage child windows from the main window, and we cannot access window or window.document directly. We instead pull the window from React context (e.g. const win = useWindow()) to ensure we're using the correct window regardless of where a view is rendered. There are some uses of window/document inside of pdnd that I'm hoping can be updated to use a provided window param instead if it is passed. For example, react-dnd supports passing the window as the context param to their DndProvider (source). Another example would be downshift which supports passing the window as an environment param (docs).
// An example of our current usage of react-dndfunctionExampleComponent(){constwin=useWindow();return(<DndProviderbackend={HTML5Backend}context={win}>{children}</DndProvider>);}
Below is an example of how this could potentially look in pdnd
// An example of passing window to pdnd in the futurefunctionExampleComponent(){constref=useRef<HTMLDivElement|null>(null);constwin=useWindow();useEffect(()=>{constelement=ref.current;if(!element)return;returncombine(draggable({
element,environment: win,// ... other params}),dropTargetForElements({
element,environment: win,// ... other params}),);},[win]);return<divref={ref}>Dragme</div>;}
I've only briefly looked at the pdnd source code and saw that there might be a chance to thread it through draggable to adapater.registerUsage and ultimately to mount. But I don't want to oversimplify the changes, as I'm not aware of all the places that access window or document. Let me know if this is something you all would be open to! It would be a massive help to us in our effort to adopt pdnd here at Slack.
The text was updated successfully, but these errors were encountered:
👋🏾 Hello again! After getting around the
react-dnd
issue I described in #106, I was able to use pdnd to support drag and drop in some feature code here at Slack 🚀 . Overall it was pretty smooth, though I'm reaching out with a request that will help me release the change. The request is to optionally support passingwindow
as a param.For context, the Slack desktop client supports multiple windows. Drag and drop works great in our "main" window, though it doesn't work if you open a view in a separate "child" window. We manage child windows from the main window, and we cannot access
window
orwindow.document
directly. We instead pull thewindow
from React context (e.g.const win = useWindow()
) to ensure we're using the correctwindow
regardless of where a view is rendered. There are some uses ofwindow
/document
inside of pdnd that I'm hoping can be updated to use a providedwindow
param instead if it is passed. For example,react-dnd
supports passing thewindow
as thecontext
param to theirDndProvider
(source). Another example would bedownshift
which supports passing thewindow
as anenvironment
param (docs).Below is an example of how this could potentially look in pdnd
I've only briefly looked at the pdnd source code and saw that there might be a chance to thread it through
draggable
toadapater.registerUsage
and ultimately tomount
. But I don't want to oversimplify the changes, as I'm not aware of all the places that accesswindow
ordocument
. Let me know if this is something you all would be open to! It would be a massive help to us in our effort to adopt pdnd here at Slack.The text was updated successfully, but these errors were encountered: