react-spectrum
react-spectrum copied to clipboard
Enter and Space should activate long presses
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
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
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.