-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[system] sx
prop supplied as a function of theme causes a warning
#27492
Comments
I remember we had a discussion about this API in #23053, I could find this comment - #23053 (comment) The idea we had at the start was that the values are anyway pulled from the theme, so it may not be needed as an API, but I can see now this use-case for spreading mixins. I think we can add this API. @mui-org/core for opinion. |
I just ran into a situation where this would be very useful and where |
sx
prop supplied as a function of theme causes a warning
I think this is worth adding as an API. @hbjORbj would you be interested in giving it a try? :) |
@AsemK @TheUnlocked Thanks for the report. It is worth mentioning that
is not true. You will find that theme properties like You can check out this demo: https://codesandbox.io/s/basictabs-material-demo-forked-dwslp?file=/demo.js |
There is a similar issue sx prop as a function for type safety #26631. However, the motivation is for type safety, which different from what I am describing here.
Current Behavior 😯
sx
prop is expected to be an object where single properties can be functions oftheme
. Supplying a function for thesx
prop instead of an object works! but gives a warning:Warning: Failed prop type: Invalid prop "sx" of type "function"
Expected Behavior 🤔
It should be allowed to supply a function to
sx
instead of an object. The function should taketheme
and return an object. In many scenarios, this is much better than supplying individual functions for eachsx
object property. In some use cases, it is not possible to get the desired behavior without supplying thesx
prop as a function. For example: suppose you wantTab
to be inside anAppbar
and take its full height. In that case, you can do:<Tab sx={(theme) => theme.mixins.toolbar }/>
This works in the latest release "beta.2", but gives the mentioned warning above. As a fallback, you can currently use
styled
to achieve the same thing without warning.sx
is much more convenient here in my perspective.The text was updated successfully, but these errors were encountered: