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

usePopover: non-modal popover allows page and popover to scroll when target has position: fixed

Open majornista opened this issue 3 years ago โ€ข 5 comments

๐Ÿ› Bug Report

A non-modal popover allows page and popover to scroll even when the target is fixed.

The new documentation search box feature in development includes a SearchAutocomplete combo box in a page header that has position: fixed

  1. Open https://reactspectrum.blob.core.windows.net/reactspectrum/d5aed9e2838b40d54ba7e7ba7a7a77f8fec212c6/docs/react-spectrum/index.html
  2. Enter some characters to search into the SearchAutocomplete, which should open a popover displaying the results.
  3. With the popover open, use the mouse wheel to scroll the page.

๐Ÿค” Expected Behavior

The popover should not scroll with the underlying page, but should remain positioned relative to the SearchAutocomplete.

๐Ÿ˜ฏ Current Behavior

The popover scrolls with the page on top of the SearchAutocomplete contained in the page header with position: fixed.

๐Ÿ’ Possible Solution

isNonModal should not disable usePreventScroll at:

https://github.com/adobe/react-spectrum/blob/b35d5c02fe900badccd0cf1a8f23bb593419f238/packages/%40react-aria/overlays/src/usePopover.ts#L99-L107

๐Ÿ”ฆ Context

๐Ÿ’ป Code Sample

๐ŸŒ Your Environment

Software Version(s)
react-spectrum @react-aria/[email protected]
Browser All
Operating System macOS

๐Ÿงข Your Company/Team

Adobe/Accessibility

๐Ÿ•ท Tracking Issue (optional)

#3383

majornista avatar Nov 30 '22 16:11 majornista

We discussed this some more today, there might be a couple of problems that I hadn't considered previously:

  1. Preventing scroll for isNonModal popovers (i.e. ComboBox) may end up preventing the user from clicking into the ComboBox input to move the text cursor while the popover is open. This might be a non-issue since I think the underlay is rendered independently of the usePreventScroll options changes in usePopover, but I haven't taken a closer look yet to confirm.
  2. This might break the iOS experience for ComboBoxes/SearchAutocompletes since usePreventScroll does some touch event stuff to prevent scrolling.

LFDanLu avatar Dec 01 '22 00:12 LFDanLu

I'll investigate today.

majornista avatar Dec 01 '22 14:12 majornista

@LFDanLu See https://github.com/adobe/react-spectrum/pull/3809 to test Storybook examples before and after the simple fix:

  1. To test behavior before any fix, open the new Storybook example for a ComboBox with fixed positioning: https://reactspectrum.blob.core.windows.net/reactspectrum/82d74597a0176141733a4c2366392f39ebe7811d/storybook/index.html?path=/story/combobox--fixed-positioning&providerSwitcher-express=false&providerSwitcher-toastPosition=bottom

  2. Expand the ComboBox and scroll the page using the mouse wheel.

  3. The listbox will scroll with the underlying content.

  4. To test the behavior with a simple fix that does not disable usePreventScroll within usePopover when isNonModal={true}, open the same Storybook example with the fix applied: https://reactspectrum.blob.core.windows.net/reactspectrum/e2856408a3291ed37397f721e22393b587b52d39/storybook/index.html?path=/story/combobox--fixed-positioning&providerSwitcher-express=false&providerSwitcher-toastPosition=bottom

  5. Expand the ComboBox and scroll the page using the mouse wheel.

  6. The page will not scroll when the Iistbox is expanded.

majornista avatar Dec 01 '22 17:12 majornista

We discussed this some more today, there might be a couple of problems that I hadn't considered previously:

  1. Preventing scroll for isNonModal popovers (i.e. ComboBox) may end up preventing the user from clicking into the ComboBox input to move the text cursor while the popover is open. This might be a non-issue since I think the underlay is rendered independently of the usePreventScroll options changes in usePopover, but I haven't taken a closer look yet to confirm.
  2. This might break the iOS experience for ComboBoxes/SearchAutocompletes since usePreventScroll does some touch event stuff to prevent scrolling.

I'm not noticing any difference in behavior, besides preventing scroll of the page, between the ComboBox the prevents scroll and that which does not. I can still position the cursor within the input using either the keyboard or the mouse, and the iOS experience seems unchanged.

majornista avatar Dec 01 '22 20:12 majornista

Hey, any updates regarding this?

EladBezalel avatar May 20 '24 11:05 EladBezalel