adobe / react-spectrum

A collection of libraries and tools that help you build adaptive, accessible, and robust user experiences.
https://react-spectrum.adobe.com
Apache License 2.0
12.15k stars 1.06k forks source link

React Aria Components - Popover & Scrollbar Gutter #5470

Open rshackleton opened 7 months ago

rshackleton commented 7 months ago

Provide a general summary of the issue here

When a popover is opened with isNonModal={false} the html element has padding added to handle the scrollbar disappearing. However, there is the new CSS property scrollbar-gutter: stable which handles this automatically. These conflict and cause the page contents to jump due to the additional padding.

๐Ÿค” Expected Behavior?

The page content shouldn't jump when a popover is opened with scollbar-gutter: stable applied to the html element.

๐Ÿ˜ฏ Current Behavior

The page content jumps when a popover is opened with scollbar-gutter: stable applied to the html element.

๐Ÿ’ Possible Solution

I see two options:

  1. Add a new option to opt-out of the automatic padding.
  2. Update to apply scrollbar-gutter: stable instead of the padding.

๐Ÿ”ฆ Context

No response

๐Ÿ–ฅ๏ธ Steps to Reproduce

https://codesandbox.io/p/sandbox/funny-water-5tdptj

Version

"react-aria-components": "1.0.0-rc.0"

What browsers are you seeing the problem on?

Chrome

If other, please specify.

No response

What operating system are you using?

macOS 12.3

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

snowystinger commented 7 months ago

Looks like Safari doesn't support it yet https://caniuse.com/mdn-css_properties_scrollbar-gutter

Possibly dupe https://github.com/adobe/react-spectrum/issues/1216

reidbarber commented 7 months ago

Webkit bug link: https://bugs.webkit.org/show_bug.cgi?id=167335

mutewinter commented 5 months ago

https://github.com/adobe/react-spectrum/assets/305901/43a05a74-e2b6-4fc9-bd07-c78e13c7ce47

Here's a video of what this looks like in Safari 17.2.1 on macOS with "react-aria-components": "1.0.1",.

sleonia commented 4 months ago

@mutewinter @snowystinger @reidbarber @rshackleton @kamal Hi. I've discovered a workaround for this issue. It involves adding extra padding to the body, which helps to prevent shifts in the layout

// somewhere in the html template
const scrollbarVisible = (element: HTMLElement) => {
  return element.scrollHeight > element.clientHeight;
};

const observer = new MutationObserver((mutations) => {
  if (mutations[0].type === "attributes") {
    if (scrollbarVisible(document.documentElement)) {
      document.body.style.paddingRight =
        document.documentElement.style.paddingRight;
    } else {
      document.documentElement.style.paddingRight = "0";
    }
  }
});

observer.observe(document.documentElement, {
  attributes: true, // This tells the observer to watch for changes in attributes
  attributeFilter: ["style"],
  subtree: false,
  attributeOldValue: false,
});
denisorehovsky commented 2 months ago

Any update on this?

https://github.com/adobe/react-spectrum/assets/9641784/1f0dc48e-1d38-4b4b-bdc8-7301eead65b1

Chrome works perfectly fine. Only Safari has problems.

MantvidasMiskinis commented 2 months ago

Hey, I am using usePopover from react-aria. Scroll is always visible on my PC browser. After opening popover, scroll disappears and it causes page content resizing. Its can be reproduced on the documentation page https://react-spectrum.adobe.com/react-aria/usePopover.html - just need to click Open Popover button and have your browser scroll always visible. I am using mac with chrome but its can be reproduced on windows too.