Open Talor-A opened 1 year ago
I think applying a data attribute to the html
element would be reasonable, we actually do the following to check if scrolling is prevented ourselves:
https://github.com/adobe/react-spectrum/blob/b57b3af44c345d456658e2895bb9244c65f0e7d3/packages/%40react-aria/utils/src/scrollIntoView.ts#L87
we actually do the following to check if scrolling is prevented ourselves
thanks. that got me thinking, subscribing to this value using a mutation observer is a reasonable workaround for the time being!
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutationRecord) {
console.log('style changed!');
});
});
var target = document.querySelector('html')
observer.observe(target, { attributes : true, attributeFilter : ['style'] });
π Feature Request
we have a header component with
position:fixed
overlaid on the main body content. when a modal, menu, or popover opens, padding is added to the<html>
element to compensate for the removed scrollbar.however, no padding is added to our fixed position
<header>
, so the content inside jumps a number of px equal to the size of the scrollbar. this means that menu triggers in the header move around, so they become much harder to toggle!it would be great to have a way to know that scrolling has been locked, so that we could apply custom styles to any elements that need it besides the body.
π€ Expected Behavior
make the state of
usePreventScroll
consumable from outside the context of the components that call the hookπ― Current Behavior
there's no way to know whether scroll is being prevented. it's applied via inline styles onto the
html
element, and the state is stored in a locally scoped variablepreventScrollCount
π Possible Solution
there are many ways to solve for this:
data-scroll-prevented
attribute to thehtml
element when locking scroll. this would allow using css selectors, event listeners, or observers to subscribe to the state.class
to thehtml
element.useIsScrollPrevented
hook that allows subscribing to state in js-land. this would probably mean changingpreventScrollCount
to some kind of basic observable value / EventTarget, since it would be undesirable to useReact.Context
. I don't see an existing global state management solution inreact-aria
, but anything would work.happy to help ship a feature if we can decide on the best path forward!
π¦ Context
π» Examples
examples implementing the three suggestions above, respectively:
π§’ Your Company/Team
https://replit.com
π Tracking Ticket (optional)
(private: https://linear.app/replit/issue/I2C-125)