useRadio and useCheckbox cause ui jumps on Safari through usePress and focusWithoutScrolling
๐ Bug Report
I've found out that clicking on radio or checkbox elements controlled by useRadio or useCheckbox hooks causes UI jumping on Safari and even worse, for mobile devices, it leaves shifted viewport after keyboard hide if previous focused element was text input.
Desktop Safari:

Mobile Safari:
https://user-images.githubusercontent.com/26162660/118660290-5587e180-b7ee-11eb-9b03-61917502dda8.MP4
I've found out that the source of the problem is focusWithoutScrolling function which gets called in usePress hook which is used by both of the hooks above. Happily enough I was able to wrap the components with <PressResponder> and pass preventFocusOnPress prop there which fixed it. Im still reporting this since this is undoubtedly unexpected behavior
๐ค Expected Behavior
usePress within useRadio and useCheckbox:
- does not affect ui in any way
- does not prevent default scroll event (after hiding a keyboard) from executing
๐ฏ Current Behavior
usePress within useRadio and useCheckbox:
- shifts UI
- prevents natural scroll behavior after keyboard hide, leaving the viewport shifted
๐ Possible Solution
Maybe pass preventFocusOnPress to usePress by default in useRadio in useCheckbox or at least expose this prop through those hooks?
๐ฆ Context
Forms in scrollable UI like chat provided bad UX for Safari users.
๐ป Code Sample
I tried providing simple example with codesandbox but could not replicate it there, Im willing to answer any questions about the setup though ๐
๐ Your Environment
| Software | Version(s) |
|---|---|
| react-spectrum | @react-aria/radio: 3.0.0-nightly.1037 |
| Browser | Safari Version 14.0.3 |
| Operating System | MacOs Big Sur 11.2.3 |
๐งข Your Company/Team
LiveChat Chat Widget
๐ท Tracking Issue (optional)
I wouldn't use preventFocusOnPress. That's the main reason for using usePress in these components in the first place - Safari doesn't focus these inputs by default so we need to focus them manually on press to ensure users can use the keyboard with them.
I'm not sure about the scrolling behavior. What would you expect to happen when the keyboard hides? I guess some scrolling would be expected because the viewport got larger?
The main problem is that on mobile Safari the viewport doesnt get larger in our case - the keyboard hides but it doesnt free up the space that it was taking.
I'm currently getting the same issue in Chrome (firefox seems to be working ok). In my application I am rendering a list of RadioGroups inside a full page height scrollable container. If you add a new RadioGroup list item and click on one of its Radios, the UI jumps and the viewport gets shifted up leaving whitespace at the bottom of the browser window. Subsquent clicks on the same Radio do not shift the viewport further. I suspect it's something to with focusing an element inside of a scrollable container.
Are there any solutions for this? Getting the same behaviour in chrome if Radio element is in a scrollable container