material icon indicating copy to clipboard operation
material copied to clipboard

$mdDialog position should be "fixed", not "absolute"

Open stefan-dimitrov opened this issue 11 years ago • 25 comments

When the body overflows and is scrolled the dialog moves with the content. For example, we have the content at topmost position and everything looks good: screenshot from 2014-12-12 16 43 17

... until we scroll down: screenshot from 2014-12-12 16 43 44

stefan-dimitrov avatar Dec 12 '14 15:12 stefan-dimitrov

Same problem applies for the md-sidenav

stefan-dimitrov avatar Dec 12 '14 15:12 stefan-dimitrov

@stefan-dimitrov is your content inside md-content? I think if you don't use that you run into this problem since md-content is what handles the scrolling.

epelc avatar Dec 12 '14 17:12 epelc

same problem here, using md-content too

fabiobiondi avatar Dec 12 '14 22:12 fabiobiondi

@epelc, my content is inside md-content but unless I specify an exact value for the height the md-content container just stretches to fit what's inside it. flex or layout-fill or height in percentages do not work.

stefan-dimitrov avatar Dec 12 '14 22:12 stefan-dimitrov

@stefan-dimitrov try specifying a layout on all the parent elements. If that doesn't work I'll make a plunkr later tonight with a basic layout.

epelc avatar Dec 12 '14 22:12 epelc

@epelc it worked, thank you. Although not how I was thinking it should've worked. Turns out the <body> needs to have a layout attribute, for the md-content to work.

At first I was trying with a topmost <div> container like so:

...
</head>
  <body>

  <div layout="column" layout-fill>
    <md-toolbar>
      <div class="md-toolbar-tools">
        <span>{{pageTitle}}</span>
      </div>
    </md-toolbar>

    <md-content flex>
      <div ui-view="main"></div>
    </md-content>
  </div>

  </body>

and it wasn't working. I don't know why, I always thought that it should work like that.

But doing it like so:

...
</head>
  <body layout="column">

    <md-toolbar>
      <div class="md-toolbar-tools">
        <span>{{pageTitle}}</span>
      </div>
    </md-toolbar>

    <md-content flex>
      <div ui-view="main"></div>
    </md-content>

  </body>

seems to be the correct way I guess.

stefan-dimitrov avatar Dec 13 '14 15:12 stefan-dimitrov

That's how I do it except I use row on the body since I have a sidenav.

epelc avatar Dec 13 '14 15:12 epelc

This doesn't solve the problem for me. Moreover, if I click on a button to open a dialog AFTER scrolling down the page, the dialog opens at the top of the page, it scrolls to the top but not entirely. schermata 01-2457025 alle 17 34 04

Also, I wonder if setting "layout" to every parent could really be a solution. Which still doesn't solve the problem to me.

davideoliveri avatar Jan 02 '15 17:01 davideoliveri

Can we reopen this issue? This is not solved for me, either.

In addition, this should be linked to #908

SebiH avatar Jan 15 '15 09:01 SebiH

The following css worked for me:

md-backdrop.md-opaque.md-default-theme,
.md-dialog-container {
  position:fixed;
}

heikkilamarko avatar Jan 17 '15 22:01 heikkilamarko

@SebiH @davideoliveri - please provide plunkr or codepens so we can analyse the issue for your configuration.

ThomasBurleson avatar Jan 17 '15 23:01 ThomasBurleson

@ThomasBurleson Taken (and updated) from #908: http://plnkr.co/edit/FmBGZ3G0Y71vh0z7Ffrm?p=preview

SebiH avatar Jan 17 '15 23:01 SebiH

I was cleaning the above plunker adding the "md-actions" class and I found it doesn't lock the scroll anymore. Nonetheless it works weirdly. http://plnkr.co/edit/zizcq45x9D6r79ih6mMj?p=preview

davideoliveri avatar Jan 18 '15 21:01 davideoliveri

Was also having this issue. Added a layout to the body like @epelc suggested and everything is working perfectly fine now. To whoever comes across this problem, just make sure that all parents of your md-content have a layout="column" or layout="row".

zilions avatar Mar 14 '16 03:03 zilions

@zilions be careful. layout="rowOrColumn" attributes on the body tag are dangerous in some situations and no longer recommended.

Try to get it working without the layout directly on the body if you can. My advice about the parents going up to body still stands though.

epelc avatar Mar 14 '16 03:03 epelc

@epelc can you suggest a way to achieve this without layout on the body? Tried quite a few things, and layout was the only thing that fixed this issue for me.

zilions avatar Mar 14 '16 03:03 zilions

@zilions height: 100%; min-height:100%; should work

On Sun, Mar 13, 2016 at 11:44 PM, zilions [email protected] wrote:

@epelc https://github.com/epelc can you suggest a way to achieve this without layout on the body? Tried quite a few things, and layout was the only thing that fixed this issue for me.

— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/932#issuecomment-196124656.

Thank you, Ed Pelc

epelc avatar Mar 14 '16 03:03 epelc

@epelc No luck. Although it does work if I add display:flex along with your styles. Is that a dodgy workaround?

zilions avatar Mar 14 '16 03:03 zilions

Maybe? If it works it works though.

I'd just test it in the different browsers to make sure it's not collapsing or anything weird. You may also run into issues with toasts and dialogs so test them.

On Sun, Mar 13, 2016 at 11:54 PM, zilions [email protected] wrote:

@epelc https://github.com/epelc No luck. Although it does work if I add display:flex along with your styles. Is that a dodgy workaround?

— Reply to this email directly or view it on GitHub https://github.com/angular/material/issues/932#issuecomment-196128447.

Thank you, Ed Pelc

epelc avatar Mar 14 '16 03:03 epelc

@epelc After a ton of testing, this method seems like the wrong path to go down. By having md-content as the scrolling element within the application instead of the body tag, most mobile devices (especially iOS) won't scroll to the top of the page when the status bar is tapped on. This removes some native functionality for the user on iOS devices since most assume they can scroll to the top with this function.

I haven't looked into any code, although it seems to be like the md-dialog uses the scroll top of the md-content to determine where to place it. Is it possible to use body instead?

zilions avatar Mar 14 '16 05:03 zilions