While working with the Dialog component, @JessWallin and I noticed that we're not locking the scroll of the page behind the Dialog when it's open. This is something we should be doing:
The documentation for the "real" HeadlessUI mentions it
The code for how the React implementation does this is here
This PR adds a modifier to Dialog that follows the exact same approach as the React version to locking the page scroll.
The one difference is that the React implementation applies the styles to document.documentElement, which is the html element, while we decided to use $portalRoot (which is likely document.body instead). This seems to work just as well, and we looked around online for other instances of scroll-locking; many of them style body rather than html. Using $portalRoot means that only the test preview window is locked, which seemed like a helpful way for us to avoid messing with the QUnit UI during tests that make use of Dialog!
While working with the
Dialog
component, @JessWallin and I noticed that we're not locking the scroll of the page behind theDialog
when it's open. This is something we should be doing:This PR adds a modifier to
Dialog
that follows the exact same approach as the React version to locking the page scroll.The one difference is that the React implementation applies the styles to
document.documentElement
, which is thehtml
element, while we decided to use$portalRoot
(which is likelydocument.body
instead). This seems to work just as well, and we looked around online for other instances of scroll-locking; many of them stylebody
rather thanhtml
. Using$portalRoot
means that only the test preview window is locked, which seemed like a helpful way for us to avoid messing with the QUnit UI during tests that make use ofDialog
!PR co-authored by @JessWallin