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

useRadio and useCheckbox cause ui jumps on Safari through usePress and focusWithoutScrolling

Open BartoszGamza opened this issue 5 years ago โ€ข 4 comments

๐Ÿ› 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:

CleanShot 2021-05-18 at 15 13 01

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)

BartoszGamza avatar May 18 '21 13:05 BartoszGamza

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?

devongovett avatar May 19 '21 18:05 devongovett

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.

Andarist avatar May 20 '21 05:05 Andarist

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.

aidan-keay avatar Aug 26 '21 16:08 aidan-keay

Are there any solutions for this? Getting the same behaviour in chrome if Radio element is in a scrollable container

ivan-palatov avatar Aug 14 '24 10:08 ivan-palatov