Skip to content

bug(mat-sidenav): sidenav really does break position: sticky #23108

@chrissena

Description

@chrissena

Reproduction

Use StackBlitz to reproduce your issue:

Steps to reproduce:

  1. Add a sticky element inside a mat-sidenav-content
  2. Element will not stick to the top of the screen
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: material/sidenavneeds: clarificationThe issue does not contain enough information for the team to determine if it is a real bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions