Material-ui: [Popper] Position offset when the container is placed with margin-left:auto

Created on 17 May 2019  路  4Comments  路  Source: mui-org/material-ui

  • [x] This is not a v0.x issue.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 馃


image

Current Behavior 馃槸


image

Steps to Reproduce 馃暪

Link: https://codesandbox.io/s/flamboyant-goldwasser-d6hrb?fontsize=14

  1. Hover over icon button

Context 馃敠

The problem is related to layout of the parent dom elements as well. The parent element of the popper anchor must be styled with margin-left:auto and the body should not have any padding or margin.

Possible Solution 馃

https://github.com/mui-org/material-ui/compare/next...FStuerzlinger:patch-1

After initializing Popper JS, a scheduled Update fixes the layout problem.
It seems that popper is not able to determine the correct possition of the anchor element upfront. Triggering popper.scheduleUpdate() triggers a revalidation of the popper positions after layout.

Your Environment 馃寧

| Tech | Version |
|--------------|---------|
| Material-UI | v3.9.3 |
| React | 16.8.6 |
| Browser | Chrome,Firefox,IE |

bug 馃悰 Popper external dependency

Most helpful comment

I believe I have narrowed down this issue and I've submitted a PR that fixes the original sandbox.

All 4 comments

@FStuerzlinger Thanks for the report. My answer would be the same as for #15194. This is a core issue with popper.js. It should be fixed at their level. If you can provide a reproduction with the library and report the problem on their side, it would be perfect. On a side note, it doesn't happen on MacOS. It seems to be a Windows thing.

@FStuerzlinger I have experienced the same problem, and thanks to you submitting this issue I've also been able to identify the cause as margin-left: auto. I've found a solution that works for me, though I do agree it should be fixed in the popper.js.

In your codesandbox, you can set margin-left: calc((100vw - 200px) / 2);. This is far from ideal and may not work in all situations, but I thought I'd leave this here in case anybody needs a quick fix while waiting for a proper solution from popper.js.

I believe I have narrowed down this issue and I've submitted a PR that fixes the original sandbox.

Yes, that seems to fix the issue for me 馃憤
Thank you 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

revskill10 picture revskill10  路  3Comments

mb-copart picture mb-copart  路  3Comments

activatedgeek picture activatedgeek  路  3Comments

iamzhouyi picture iamzhouyi  路  3Comments