Material-ui: Using tabs inside a popover incorrectly calculates the left offset based on bounting box calculations

Created on 20 Feb 2020  路  8Comments  路  Source: mui-org/material-ui

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸


Opening a popover that contains tabs incorrectly determines the 'start' position of the indicator, which appears offset from the page, not the containing popover

Expected Behavior 馃


The start position of the indicator should be calculated from the containing element.

It looks like this issue https://github.com/mui-org/material-ui/issues/9337 but it is not, because when we implement the useEffect solution it still does not correctly calculate the offset.

Looking at the internal material code something is going wrong in calculating tabMeta.left - tabsMeta.left on load because the laculation ends up being 16 - 173 (in our example), but if I change tab and then change back it correctly works out that it's 16 - 16. It's as though the tabsMeta calculates it's boundingClientRect too soon.

Steps to Reproduce 馃暪

Edit Material demo

Steps:

  1. Create a component using popover
  2. Put tabs inside
  3. Notice the indicator is offset incorrectly
  4. cry

Attempts to fix

Edit Material demo

Tries to use a setTimeout in a useEffect.

Context 馃敠

Tabs in a popover

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | ^4.5.3 |
| React | ^16.10.2 |
| Browser | Chrome |

duplicate

Most helpful comment

I call updateIndicator() in an onEntered callback.

All 8 comments

@AncientSwordRage We appreciate the time spend in the issue description and reproduction, but I'm closing as a duplicate #9337.

but it is not, because when we implement the useEffect solution it still does not correctly calculate the offset.

Consider the impact of the animation running.

but it is not, because when we implement the useEffect solution it still does not correctly calculate the offset.

Consider the impact of the animation running.

How would one do that?

You could use a setTimeout to account for it.

Set timeout doesn't have any effect. I can update the example to reproduce with what I've attempted.

You could use a setTimeout to account for it.

Edited main issue with my attempt to fix there.

@oliviertassinari I've also tested with useLayoutEffect and it made no difference.

I call updateIndicator() in an onEntered callback.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryanflorence picture ryanflorence  路  3Comments

revskill10 picture revskill10  路  3Comments

activatedgeek picture activatedgeek  路  3Comments

rbozan picture rbozan  路  3Comments

mattmiddlesworth picture mattmiddlesworth  路  3Comments