question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] weird(cannot) scroll after two dialog intersect showing

See original GitHub issue

https://github.com/tailwindlabs/headlessui/blob/5af3bd4b7164a0205ac70c179d8e9651afbb0a72/packages/%40headlessui-react/src/components/dialog/dialog.tsx#L254

  • DialogA:LoadingMask shows
  • do some fetching
  • done fetching
  • DialogB:Confirmation shows
  • DialogA:LoadingMask hides
    • expected: html style has overflow:hidden
    • actually: html style is empty
  • click confirm
  • DialogB:Confirmation hides
    • expected: html style is empty
    • actually: html style has overflow:hidden

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Ding-Fancommented, Aug 15, 2022

I’m using this as a workaround

        // prevent scroll bug
        // https://github.com/tailwindlabs/headlessui/issues/1698
        const HTMLDOM = document.querySelector('html')

        if (HTMLDOM) {
          // https://stackoverflow.com/a/67384208/6236633
          // HTMLDOM.style = ''
          HTMLDOM.setAttribute('style', '')
        }

example:

//
// utils.ts
//
  export const preventScrollBug = () => {
    // prevent scroll bug
    // https://github.com/tailwindlabs/headlessui/issues/1698
    const HTMLDOM = document.querySelector('html')

    // console.log('html dom', HTMLDOM)

    if (HTMLDOM) {
      // https://stackoverflow.com/a/67384208/6236633
      // HTMLDOM.style = ''
      HTMLDOM.setAttribute('style', '')
    }
  }

//
// my custom loading mask
//
/* ... */
    <Transition appear show={showMask}
      afterLeave={() => {
        setTimeout(() => {
          Utils.preventScrollBug()
        })
      }}
/* ... */

This will make sure the html can scroll

1reaction
thecrypticacecommented, Jul 29, 2022

Okay, I talked with @RobinMalfait some and we actually don’t support multiple open sibling dialogs. It is definitely something we want to support but there will likely be more we have to change to properly support that. In the short term you might be able to work around the issue by nesting the dialogs/modals inside one another as children. This allows us to properly restore state. This is also why the ESC closes the first modal first and not the second one.

I’m closing this for now (sorry!) but will keep it on the mind for when we do eventually find a way to properly support multiple open dialogs that are siblings.

Here’s a comment from an earlier issue with some examples with nested versus sibling dialogs: https://github.com/tailwindlabs/headlessui/issues/426#issuecomment-1059185316

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple/nested Dialog instances bugs · Issue #426 - GitHub
I played around dialog component and find some issues: scroll jumping, described here: [Bug]: Modal jumps horizontally when closing (on Windows ...
Read more >
Disable scrolling while popup active - Stack Overflow
A simple answer, which you could use and would not require you to stop the scroll event would be to set the position...
Read more >
overscroll-behavior - CSS: Cascading Style Sheets | MDN
If you have overscroll-behavior: contain; selected, the outer container will not scroll unless you move your cursor out of the inner container ...
Read more >
Displaying Bitmap with Scrolling - CodeProject
An article showing how to display a picture within a dialog, and add scrollbars where needed to view the whole image.
Read more >
Scroll Events and Intersection Observer - Beginner JavaScript
In this video we will learn about scroll events. A scroll event is when someone goes ahead and scrolls on the page or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found