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

[material-ui] Tabs component indicatorColor does not accept custom theme colors #42274

Open
mattixittam opened this issue May 17, 2024 · 1 comment
Assignees
Labels
component: tabs This is the name of the generic UI component, not the React module! new feature New feature or request package: material-ui Specific to @mui/material

Comments

@mattixittam
Copy link

mattixittam commented May 17, 2024

Steps to reproduce

Link to live example: Example

Steps:

  1. Define a custom theme color, I went with 'aCustomColor'
  2. Use the color in the indicatorColor prop: <Tabs indicatorColor="aCustomColor">[...]</Tabs>

Current behavior

The Tabs component does not accept custom theme colors for the indicator

Expected behavior

I would like the Tabs component to accept custom theme colors for the indicator

Context

I want to have the option to use a custom theme color in some places instead of the primary/secondary options that are now hardcoded into the component css.

Your environment

Environment as in the example code sandbox, so nothing special or custom.

Search keywords: indicator, tabs, custom color, theme

@mattixittam mattixittam added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label May 17, 2024
@mattixittam mattixittam changed the title [Material UI] Tabs component indicatorColor does not accept custom theme colors [material-ui] Tabs component indicatorColor does not accept custom theme colors May 17, 2024
@zannager zannager added the component: tabs This is the name of the generic UI component, not the React module! label May 17, 2024
@mnajdova
Copy link
Member

Thanks for the report. We can improve the support for this, by applying the following diff:

index 3bafb2efbb..8b6e49ef43 100644
--- a/packages/mui-material/src/Tabs/Tabs.js
+++ b/packages/mui-material/src/Tabs/Tabs.js
@@ -234,22 +234,12 @@ const TabsIndicator = styled('span', {
   width: '100%',
   transition: theme.transitions.create(),
   variants: [
-    {
-      props: {
-        indicatorColor: 'primary',
-      },
-      style: {
-        backgroundColor: (theme.vars || theme).palette.primary.main,
-      },
-    },
-    {
-      props: {
-        indicatorColor: 'secondary',
-      },
-      style: {
-        backgroundColor: (theme.vars || theme).palette.secondary.main,
-      },
-    },
+    ...Object.entries((theme.vars ?? theme).palette)
+      .filter(([, value]) => value && value.main)
+      .map(([color]) => ({
+        props: { indicatorColor: color },
+        style: { backgroundColor: (theme.vars ?? theme).palette?.[color]?.main },
+      })),
     {
       props: ({ ownerState }) => ownerState.vertical,
       style: {

Would you like to create a PR with this change? We can also add test to ensure it won't be changed in the future.

@mnajdova mnajdova added new feature New feature or request and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels May 20, 2024
@danilo-leal danilo-leal added the package: material-ui Specific to @mui/material label May 21, 2024
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! new feature New feature or request package: material-ui Specific to @mui/material
Projects
None yet
Development

No branches or pull requests

4 participants