GavinJoyce / ember-headlessui

https://gavinjoyce.github.io/ember-headlessui/
Other
92 stars 34 forks source link

fix(dialog): lock scroll when the dialog is open #110

Closed alexlafroscia closed 3 years ago

alexlafroscia commented 3 years ago

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:

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!

PR co-authored by @JessWallin

alexlafroscia commented 3 years ago

Rebased to add those recommended comments -- thanks @NullVoxPopuli!