react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

Enter and Space should activate long presses

Open jamiebuilds opened this issue 1 year ago โ€ข 1 comments

Provide a general summary of the feature here

Enter and Space are both used as alternatives in usePress(). However, keyboard events are explicitly filtered out from useLongPress(). The documentation does warn that you should provide an alternative, which makes sense given that some users will not be able to hold a key easily.

But there's still a use case for allowing Space and Enter to perform a long press, for example it's a common interaction for "temporary pausing" such as a in carousels or 'Stories' features in many social apps.

๐Ÿค” Expected Behavior?

Space and Enter should activate long presses

๐Ÿ˜ฏ Current Behavior

Space and Enter do not activate long presses

๐Ÿ’ Possible Solution

No response

๐Ÿ”ฆ Context

Had to reimplement useLongPress() in order to get this behavior

๐Ÿ’ป Examples

No response

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

jamiebuilds avatar May 06 '24 19:05 jamiebuilds

Are those actually long presses? I tried Stories with touch, and it pauses until the press is ended. But long press finishes after about half a second, which would be a different behavior. If you used useLongPress for this, it'd only pause the video for half a second and then it would resume. Seems like useLongPress isn't the right thing to use for this interaction pattern to begin with?

It also doesn't take a long press for the keyboard version of the interaction, just a quick tap of the 'Space' key will pause a video.

Maybe you can provide more details about what you're building, or an example app? Maybe some interaction patterns are being conflated. For instance, I think you can just use usePress with onPressStart and onPressEnd and use the interaction mode to determine what actions to take.

Something along these lines? Touch: pause on press start, resume on press end Mouse: toggle pause on press Keyboard: toggle pause on press

snowystinger avatar May 07 '24 23:05 snowystinger

We did not include keyboard interactions in useLongPress by default because they often differ between components. For example, in a button with both normal and long press mouse/touch interactions, you might use Alt + Enter or Alt + ArrowDown to open a long press menu. We could potentially make it configurable, but it doesn't seem too hard to use useLongPress in combination with your own onKeyDown listener either.

devongovett avatar Jul 30 '24 15:07 devongovett