-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Description
Reproduction
Use StackBlitz to reproduce your issue:
- Components: https://stackblitz.com/edit/components-issue-jfapkp?file=src%2Fapp%2Fexample-component.html
Steps to reproduce:
- Add a sticky element inside a mat-sidenav-content
- Element will not stick to the top of the screen
- Unsetting display: block on mat-sidenav-container fixes this but breaks the sidenav itself
This is a copy of #16443 but that issue is locked due to inactivity so I have created this.
@jelbourn's answer:
(revisiting older issues as part of a triaging fix-it)
The problem here is that you're not actually scrolling the mat-sidenav-content element- the body element is scrolling. The way position: sticky works is that it's sticky relative to its containing element, so when the body scrolls instead, the entire mat-sidenav-content is being scrolled through the body. You can see this manifest by adding a smaller height to mat-sidenav-content and scrolling.
This doesn't make sense to me as I was under the impression that this is how position: sticky is intended to work.
See: CSS Position Sticky - How It Really Works!
specifically this codepen example
As you can see in the codepen example, the body is scrolling and taking the main element with it. The HEADER div (which has position: sticky set) sticks to the top (within the bounds of the main element).
Is this not analogous to the mat-sidenav stackblitz example above, with the mat-sidenav-content element acting like main? It seems as though sidenav is breaking the position: sticky and preventing it from working as intended.
Expected Behavior
Header div Element to stick to top when scrolling down
Actual Behavior
Header div scrolls out of view
Environment
- Angular: 12
- CDK/Material: 12
- Browser(s): chrome
- Operating System (e.g. Windows, macOS, Ubuntu): Windows