Skip to content
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

Tabs indicator wrong position & width when using transform:scale. #35631

Closed
2 tasks done
madmonliadd opened this issue Dec 26, 2022 · 7 comments
Closed
2 tasks done

Tabs indicator wrong position & width when using transform:scale. #35631

madmonliadd opened this issue Dec 26, 2022 · 7 comments
Labels
component: tabs This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow

Comments

@madmonliadd
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Steps to reproduce 🕹

Link to live example:
https://codesandbox.io/s/usage-forked-gw74rl?file=/index.js

Steps:

  1. Wrap the tabs component with a transform:scaled wrapper / use the link above.

Current behavior 😯

The tabs' indicator's position & width isn't correctly set.

Expected behavior 🤔

The tabs' indicator's position should be exactly below the selected tab, and its width should match exactly the selected tab's width.

Context 🔦

No response

Your environment 🌎

Using the codesandbox above.

@madmonliadd madmonliadd added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Dec 26, 2022
@ZeeshanTamboli
Copy link
Member

You need to target the indicator class on Tabs to style the tabs indicator. See the updated CodeSandbox: https://codesandbox.io/s/usage-forked-l1m7fu?file=/index.js

@ZeeshanTamboli ZeeshanTamboli added component: tabs This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Dec 27, 2022
@github-actions
Copy link

👋 Thanks for using MUI Core!

We use GitHub issues exclusively as a bug and feature requests tracker, however,
this issue appears to be a support request.

For support, please check out https://mui.com/getting-started/support/. Thanks!

If you have a question on Stack Overflow, you are welcome to link to it here, it might help others.
If your issue is subsequently confirmed as a bug, and the report follows the issue template, it can be reopened.

@madmonliadd
Copy link
Author

@ZeeshanTamboli You removed the scaled div, of course it'll work when you remove the parent scale.

@ZeeshanTamboli
Copy link
Member

@ZeeshanTamboli You removed the scaled div, of course it'll work when you remove the parent scale.

@madmonliadd Sorry for that, I didn't read carefully about you saying Wrap the tabs component with a transform:scaled wrapper.

I don't know why you want to achieve scaling for your use case, but you can increase the scaling by directly applying the styles to the AppBar. Having a unnecessary div in between for scaling is causing the issue of moving the position of the tab indicator. As for the width, it is calculated dynamically under the hood according to the size of the tab and considers various other factors, but you can override it with the .MuiTabs-indicator class if you want to or instead calculate it as per the scaling and apply it.

See the updated CodeSandbox: https://codesandbox.io/s/usage-forked-1y7g9f?file=/index.js

I would suggest to use StackOverflow for these type of questions.

I hope it helps.

@madmonliadd
Copy link
Author

@ZeeshanTamboli Hey, thanks for your help, I tried stack overflow without success, it's a bug, not a help request.
Your codesandbox didn't solve the issue, click other tabs and see how the position of the indicator is incorrect, it's not directly under the selected tab.

@ZeeshanTamboli
Copy link
Member

it's a bug, not a help request.

It's not a bug. It's just about overriding with the correct styles.

You have to simply find a way to style the tab indicator properly. Maybe you want to check if you are correctly using transform: scale property. You may not want to scale the indicator or maybe you shouldn't use the scale on tabs in the first place and use sizing. Take a look at the customization of Tabs docs: https://mui.com/material-ui/react-tabs/#customization

@carmenchapa
Copy link

In case someone else lands here.
I faced this problem in an app where scaling a parent container was not up to me.
I could fix it by overriding left style of indicator like below. In my case the fixed values worked.

const indicatorLefts = {
  first: '0px',
  second: '50px',
  third: '100px',
}
....

<Tabs
  ...
    sx={{
      '& .MuiTabs-indicator': {
       left: `${indicatorLefts[activeTab]} !important`,
     }
   }}
>
...
</Tabs>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: tabs This is the name of the generic UI component, not the React module! support: Stack Overflow Please ask the community on Stack Overflow
Projects
None yet
Development

No branches or pull requests

3 participants