(sidenav) elements with `position: fixed` inside `md-sidenav-layout`
Because of transform: translate3d(0, 0, 0) on md-sidenav-layout any element with position: fixed inside it will act as if it had position: absolute or static instead. It's an expected behaviour, but it's annoying nevertheless.
Could we either remove that transform from md-sidenav-layout(it's only there because of performance I suppose), or add more examples to Portal and mention it as a workaround in docs, since portal could probably solve this by basically putting the element that needs to be fixed next to the md-sidenav-layout in the dom tree.
cc @hansl @jelbourn
https://gist.github.com/fxck/b668f7fec77d7b28d8c7ce6b706601f7
here's a component that takes whatever is inside it and puts it to the body using material2 overlay
@jelbourn this is still a thing, can you label it please?
We need to discuss whether we consider this a bug or not.
In my opinion this is a bug insofar as it is the equivalent of putting a ban on fixed elements. I am now trying to create a fab button on the bottom right corner of the screen. Because of this issue I'm unable to do so unless I use solution provided by @fxck
Is the workaround from @fxck still working?
I am getting EXCEPTION: Must provide a portal to attach...
I recommend just absolutely positioning the fab outside the scrollable region: http://plnkr.co/edit/VItn3Y2AaTzpzIykTTyH?p=preview
that's clever @mmalerba but it wouldn't work in my case. My button is inside a router outlet as the fab is not always needed. Your solution would work great for cases where fixed elements should be visible in every view though.
Also, it would mean a lot of boilerplate to pass events to other components within the scrollable area
@bergben it is. I'm using material alpha 10 and it still works. It took me a bit to get it working though. Could you post what you have?
@cortopy It was kinda late yesterday, the problem was that I simply forgot to import the Directive as well π Got some other problem now though that the sidebar is not opening / visible / whatever... What I got now is this:
<md-sidenav-layout [ngClass]="{'administration' : isLoggedIn}">
<md-sidenav #sideNav mode="push" [hidden]="!isLoggedIn" opened="true">
<noe-admin-sidenav>
</noe-admin-sidenav>
</md-sidenav>
<fnls-displacer [sideNav]="sideNav">
<noe-admin-topnav [sideNav]="sideNav" *ngIf="isLoggedIn">
</noe-admin-topnav>
<div class="content-wrapper">
<router-outlet></router-outlet>
<noe-footer></noe-footer>
</div
</fnls-displacer>
</md-sidenav-layout>
How exactly do I have to wrap the content with the displacer to get it to work? I also had to add this css to make the fixed content work:
.md-overlay-pane{
width:100%;
}
.md-overlay-container{
position:absolute !important;
}
Still couldn't resolve this. Seems like this wasn't a problem with the angular 1 version of the sidenav... Problem is, I don't only have one button that is fixed but the whole content is fixed for a certain time as I am using https://github.com/bergben/ng2-scrollimate to apply animations on the fly during scroll. So if I displace that all then there is nothing left anymore in md-sidenav-content and the sidenav itself doesn't work anymore...
#1966 adds a sidenav with fab example
@mmalerba Having a scroll inside content rather than on body brings a lot problems with UX and with fixed elements(various cases when fixed element is actually overlaying the scrollbar, or regions that appear part of scrollable areas but are not, so you are scrolling on them and the page doesn't scroll), also there are potential problems / extra set up on phones for smooth scrolling required, potential double scrollbars... meh. All this because of an unnecessary transform: translate3d(0, 0, 0). π
Take my directive, name it something better, make it a structural directive for easier use and add it to the core. It just puts everything inside it in a Overlay, nothing more, doesn't break binding in any way. Problem solved. Usable on many other places.
I do think separate scrolling areas should be the recommended solution for this. If I have a lot of content in my sidenav I probably want it to scroll independently from my content area. However I do think it currently requires a bit too much work to set up, I would like to make it easier if possible. I'm also not opposed to removing the translate3d if it really is superfluous (I need to investigate) so that people can use the fixed positioning solution if they prefer.
@jelbourn Do you have any opinions on this?
@mmalerba This solution only works if you have relatively simple fixed content, if you have it spanning over the whole page or stuff like that it just gets too complicated. What I find interesting though is that this problem didn't seem to come up in the Angular 1 version of the sidenav - as I was searching through the issues there. The translate3d could be replaced with a simple animation and basic distance property to fix this problem for good... I don't know though why the translate3d breaks a css position in the first place, this is surely a misbehavior of CSS in the first place IMO, but that's another topic.
I am using angular 2 material design, pls give a solution base on angular 2 material design and not material 1
@bergben I'm not sure I understand your template.
Simplifying a lot this is what I have in app.component.html:
<md-sidenav-layout>
<md-sidenav #start mode="side">
<my-sidenav></my-sidenav>
</md-sidenav>
<router-outlet></router-outlet>
</md-sidenav-layout>
And then in a template for a component that gets loaded by the router I have:
<fnls-displacer>
<button></button>
</fnls-displacer>
fab button not being fixed on button right position while scrolling
On Nov 29, 2016 3:38 PM, "Juan J. Jimenez-Anca" [email protected] wrote:
@bergben https://github.com/bergben I'm not sure I understand your template.
Simplifying a lot this is what I have in app.component.html:
<router-outlet></router-outlet>And then in a template for a component that gets loaded by the router I have:
β You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/material2/issues/998#issuecomment-263529150, or mute the thread https://github.com/notifications/unsubscribe-auth/AKF9fMNi-a5ccvI1k6Ot40RvfZHCmcX8ks5rC_mzgaJpZM4JiD6w .
Yeah you got that right @cortopy there are no inputs on displacer itself, it's literally just "take whatever is inside me and append it to body". It doesn't break bindings or anything, so it's as if you were wrapping it in a div. What I think he's doing is wrapping the whole router-outlet inside it, which I'm not surprised at all that doesn't work. It's really intended for buttons/modals/whatever you need appended to body from inside the router outlet.
cc @bergben
I have the fab button inside a component and this component is being called from router-outlet and the router-outlet is inside the side-nav-layout as u have described. After doing every thing the fab scrolls while scrolling data in the component which is not what I need.
On Nov 29, 2016 10:01 PM, "AleΕ‘" [email protected] wrote:
Yeah you got that right @cortopy https://github.com/cortopy there are no inputs on displacer itself, it's literally just "take whatever is inside me and append it to body". It doesn't break bindings or anything, so it's as if you were wrapping it in a div. What I think he's doing is wrapping the whole router-outlet inside it, which I'm not surprised at all that doesn't work. It's really intended for buttons/modals/whatever you need appended to body from inside the router outlet.
cc @bergben https://github.com/bergben
β You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/material2/issues/998#issuecomment-263621269, or mute the thread https://github.com/notifications/unsubscribe-auth/AKF9fBpBHTG8b78hNquET1i-TVcNbcKhks5rDFNMgaJpZM4JiD6w .
@johnl242 don't forget to style your button!! The displacer doesn't do anything in terms of styling or positioning. This is what I have
bottom: 1rem
position: fixed
right: 1rem
transform: translateZ(0)