adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.18k stars 1.06k forks source link

ListBox onAction breaks selection #6506

Open ArrayKnight opened 1 month ago

ArrayKnight commented 1 month ago

Provide a general summary of the issue here

Not sure if this is intended and undocumented or a bug

If you add an event listener to the onAction prop on the ListBox component, the standard selection behavior ceases to function

Maybe the expectation is that if you're listening to onAction you're handling all selection state externally(?)

I discovered this when implementing a story for the component and binding all event handler props to actions (logs)

๐Ÿค” Expected Behavior?

Either document this as expected behavior or allow for onAction to be listened to without breaking internal selection state management

๐Ÿ˜ฏ Current Behavior

Binding onAction causes presses to not update selection state

๐Ÿ’ Possible Solution

No response

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

https://codesandbox.io/p/sandbox/amazing-solomon-ypvhz7

Version

1.2.1

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

Mac

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

snowystinger commented 1 month ago

Looks like we left out the onAction documentation for ListBox https://react-spectrum.adobe.com/react-aria/GridList.html#row-actions

What you want though is https://react-spectrum.adobe.com/react-aria/ListBox.html#selection-behavior to set this to "Replace" Then the default interaction will be selection and a double click will trigger the action, as it mentions in the GridList docs I linked to.

Otherwise, you need to provide a control to trigger selection on individual rows.