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

Add shouldForwardProp to theme #34831

Closed
2 tasks done
andrehil opened this issue Oct 19, 2022 · 10 comments
Closed
2 tasks done

Add shouldForwardProp to theme #34831

andrehil opened this issue Oct 19, 2022 · 10 comments
Assignees
Labels
customization: theme Centered around the theming features duplicate This issue or pull request already exists new feature New feature or request package: system Specific to @mui/system

Comments

@andrehil
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

I'm using a custom property to create custom variants for OutlinedInput.
The problem is that I need to pass the property to the component for the theme to have it, but the property ends up being rendered to the DOM.

Examples 🌈

Component usage:

<OutlinedInput state="error />

Theme:

{
  "MuiOutlinedInput":{
    "variants":[
      {
        "props":{
          "state":"error"
        },
        "style":{
          "my_custom_styles":"go here"
        }
      }
    ]
  }
}

Motivation 🔦

The motivation is the same as the function shouldForwardProp that exists in styled.
Avoid rendering unnecessary properties to DOM.

@andrehil andrehil added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 19, 2022
@zannager zannager added component: text field This is the name of the generic UI component, not the React module! package: system Specific to @mui/system and removed component: text field This is the name of the generic UI component, not the React module! labels Oct 20, 2022
@siriwatknp siriwatknp self-assigned this Oct 21, 2022
@siriwatknp siriwatknp added customization: theme Centered around the theming features new feature New feature or request and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 21, 2022
@michelengelen
Copy link
Member

This would be a great feature to have and I am currently having the same issue. Is there anyone working on this and if not could you maybe point me to the respective place in the codebase where this could be added? I could add that feature myself in that case.

cc @siriwatknp

Thanks in advance!

@Armisael2k
Copy link

Any updates?

@andrehil
Copy link
Author

andrehil commented Oct 4, 2023

Please don't let this one die :)

@siriwatknp
Copy link
Member

@mnajdova A new use case for the variants API. This case needs to style based on the ownerState, not just props.

@trungutt
Copy link

trungutt commented Oct 6, 2023

We'd like to have this too

@rishavpandey43
Copy link

Hi @mnajdova

Is there any update on this, its really very helpful feature.

@mnajdova
Copy link
Member

The issue itself looks like a duplicate of #19466, it's about supporting additional props in the components. The decision is about whether creating a wrapper component as an API is easier/more intuitive in comparison with a new API about specifying which props should be propagated. I am tagging @aarongarciah so we can include this in the planning for the next theming customization/experience. If we decide to add this support in one of the next majors, we can likely backport it in v6 too.

@mnajdova mnajdova added the duplicate This issue or pull request already exists label Sep 30, 2024
@michelengelen
Copy link
Member

Duplicate of #19466

@michelengelen michelengelen marked this as a duplicate of #19466 Sep 30, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Sep 30, 2024
@rishavpandey43
Copy link

@mnajdova IMO, we can create a wrapper component and it's good when we have some additional features to add.

But for simple changes like just giving support of maxWidth in the TableCell component we will create a wrapper where we're simply returning the same component and nothing new is being done. I think adding this new functionality might be great.

@ChristianGrete
Copy link

We have the same problem, for example, that we introduce the prop dense for the IconButton via theming and module augmentation for a button variant with less padding, which technically works great, but the boolean prop is forwarded to the DOM, resulting in the following error message in Chrome:

Warning: Received `true` for a non-boolean attribute `dense`.

If you want to write it to the DOM, pass a string instead: dense="true" or dense={value.toString()}.

As far as I understand, there should be a way to override which props are forwarded in the theme for a component, like shouldForwardProps in styled. Since we maintain a whole design system's component library based on MUI, a wrapper component is not a good alternative here, as it would have to have the same feature set as an original MUI component when consumed, because this is what our users expect. A custom component therefore always means a certain overhead of code and an alternative import source of a component actually provided by MUI, which could be avoided with such a functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features duplicate This issue or pull request already exists new feature New feature or request package: system Specific to @mui/system
Projects
None yet
Development

No branches or pull requests

9 participants