Open jgarplind opened 1 week ago
@jgarplind I guess the issue lies with the overloaded usage of drag and drop for re-ordering. Even when re-ordering might infeasible, a drag action of the item remains possible (e.g. dragging item into another list), thus the warning is still required.
I think the best way forward in your scenario would be to conditionally pass undefined
to the dragAndDropHooks
property of <GridList />
👍
Thanks for weighing in!
Conditionally passing undefined was our first solution, but IIRC it broke things quite badly when the condition changed between renders on an already mounted component (React had to handle a different amount of hooks, no bueno).
Currently we have settled for letting the warning be, since we believe we know our use case good enough to ignore it, but it's still a bit unfortunate to have it slightly polluting the console.
I see - only thing that comes to mind then would be to intercept the button context and manually invoke the callback ref that's normally spread onto the drag button. This is pretty ugly but at least it gets you what you are looking for.
I don't think there are many options for the react-aria team to have this behavior built-in, besides maybe skipping the warning when the item is disabled 👍
Provide your feedback here.
We're using GridList with drag and drop for re-ordering. Depending on the dynamically sourced data, it happens that the GridList only contains one GridListItem.
When that happens, we would prefer not to have to render a
<Button slot="drag">
. However, this warning is emitted, causing us to reconsider: https://github.com/adobe/react-spectrum/blob/d8161f6a9157193da3ab66b732f660300a39b720/packages/react-aria-components/src/GridList.tsx#L337-L342I tried following the logic and found myself at https://github.com/adobe/react-spectrum/blob/69109f0036d58b0afe7b3539c69361bec934aa43/packages/react-aria-components/src/useDragAndDrop.tsx#L114
I could easily do (and tried) something like
getItems: myList.length <= 1 ? undefined : regularLogic
, and that worked fine, except, the behavior was not disabled. In other words, I could still reach thereordering
state with keyboard interactions, I just couldn't see where the focus went when it would previously have gone to the drag handle.In the end, combining
isDisabled: myList.length <= 1
with thegetItems
-shenanigans from above seems to seal the deal, but it left me with a feeling of having battled rather than collaborated with the library.I think there are a few different approaches here, and would be happy to learn which you think is most in line with how this library is intended to function:
GridList
if there are 2+ items in the list, opting for other solutions otherwise.🔦 Context
We're just battling some warnings trying to write maintainable, user friendly code.
💻 Code Sample
No response
Version
react-aria-components 1.4.1
What browsers are you seeing the problem on?
No response
If other, please specify
No response
What operating system are you using?
No response