Skip to content

bug(mat-dialog): element with fixed position jumps when dialog opens. #23851

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
liesahead opened this issue Oct 28, 2021 · 7 comments
Open
Labels
area: cdk/overlay P4 A relatively minor issue that is not relevant to core functions

Comments

@liesahead
Copy link

Reproduction

Use StackBlitz to reproduce your issue:

Steps to reproduce:

  1. Just open dialog which contains element with fixed position inside it.

Expected Behavior

Element is positioned correctly when dialog opens.

Actual Behavior

Element jumps from one position to correct one.
fixed_element_jump_in_dialog

Environment

  • Angular: in stackblitz link
  • CDK/Material: in stackblitz link
  • Browser(s): Chrome v94
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10 latest
@liesahead liesahead added the needs triage This issue needs to be triaged by the team label Oct 28, 2021
@jelbourn jelbourn added area: cdk/overlay P4 A relatively minor issue that is not relevant to core functions and removed needs triage This issue needs to be triaged by the team labels Oct 28, 2021
@jelbourn
Copy link
Member

@crisbeto I can see this jumping, and can see that's it's definitely related to the animation (NoopAnimationsModule fixes it). I'm not sure, though, what would be animating here that would affect a position: fixed element. Are we doing something that would change the offsetParent during the animation?

@crisbeto
Copy link
Member

crisbeto commented Oct 28, 2021

It's because the dialog transitions from transform: scale(0.7) to transform: none. An element with a transform creates a new stacking context for position: fixed elements. We could transition to scale(1) which will prevent the jump, but we've had issues in the past which caused the text inside the dialog to be blurry.

@liesahead
Copy link
Author

Any suggestions for a workaround?

@crisbeto
Copy link
Member

crisbeto commented Nov 4, 2021

You can avoid the jump by setting a transform on the dialog, but I'm not sure if that's what you want since the element will still be positioned relative to the dialog container. https://stackblitz.com/edit/angular-eyckbt-b5j4ud?file=src%2Fstyles.scss

The other option would be to disable animations for the entire module using the NoopAnimationsModule instead of BrowserAnimationsModule, but that might not be desirable either. There's also a PR that allows for the dialog animation to be controlled using the config object, but it has been stuck for a while #13466.

@liesahead
Copy link
Author

liesahead commented Nov 4, 2021

Thanks for the fast reply! Sadly, that #13466 would be the only one that's useful. I will probably go with the fade animation on the fixed elements.

Edit: tried to force transform to none with important flag for dialog container but it didn't work either.

Edit2: added a *ngIf="hasViewInited" with animation on element. Now element fades without jumping when dialog is opening.
image
image

@vanczatibor2
Copy link

vanczatibor2 commented Dec 2, 2022

I found a solution because for me the liesahead's answer did not solve the issue.
image
image
I am using flexlayout, but I am sure this can be solved by changing the "this.hasViewInited = true" to:
const element = document.getElementById("<the absolute components name>")
if(element){ element.style.display = 'flex' //or whatever you want. }
And also give display: none to your elements css code.

@firdausreza
Copy link

firdausreza commented Nov 30, 2023

It's because the dialog transitions from transform: scale(0.7) to transform: none. An element with a transform creates a new stacking context for position: fixed elements. We could transition to scale(1) which will prevent the jump, but we've had issues in the past which caused the text inside the dialog to be blurry.

I had the similar problem, the difference is I had a sticky elements that always jumpy when MatDialog is opened. overriding the transform property to scale(1) solves the problem. Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cdk/overlay P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

5 participants