Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

panel: mdPanelPosition.relativeTo.addPanelPosition does not work reliably/docs unclear #11849

Open
@oliversalzburg

Description

@oliversalzburg

Bug

While working on debugging mdPanel-related issues, I ran into an issue with panel size/positioning.

CodePen and steps to reproduce the issue:

CodePen Demo which demonstrates the issue: https://codepen.io/oliversalzburg/pen/ExaqaRb

Detailed Reproduction Steps:

  1. Open a panel that should be positioned relatively to another element.

What is the expected behavior?

Everything works as intended. Dialog opens at the desired position.

What is the current behavior?

In certain scenarios, the panel will open at an invalid location.

From my observations, in certain scenarios, mdPanel will attempt to calculate the position for the panel while the panel is still set to be hidden (via _md-panel-hidden). In those cases, getBoundingClientRect will return a rect with all 0. This negatively impacts the calculation whenever the size of the dialog must be taken into account.

https://github.com/angular/material/blob/master/src/components/panel/panel.js#L3117

The demo in the documentation actually sets a min-height for the dialog, which seems useless, until you realize it is the counter-measure against this behavior.

IMHO the correct solution would be to not rely on the bounding box calculations of invisible elements and instead show them before retrieving their bounds. The current approach is unreliable. However, if you hide a dialog (to later reuse it), you can not update the animation, because the panel is hidden and has a 0-rect bounding box. So the calculation is always wrong while the panel is in the hidden state and there is no way around that.

We currently believe this to also be the root cause for tooltips sometimes appearing off-screen and flying into position. For mdPanelAnimations, the bounding rect is also pulled for the openFrom argument. This can also potentially result in 0-rects and the tooltip will fly in from the origin.

Is there anything else we should know? Stack Traces, Screenshots, etc.

I'm still working through the specifics of this behavior and will add more details as they come up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4: minorMinor issues. May not be fixed without community contributions.needs: investigationThe cause of this issue is not well understood and needs to be investigated by the team or communitytype: bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions