Comments (10)
Isn't this what you are looking for @dberardo-com ?
https://mui.com/material-ui/customization/theme-components/#theme-default-props
from material-ui.
thanks for the quick reply.
i would like to keep defaultProps for native MUI element untouched, and change them only for my custom elements
from material-ui.
In that case, have you considered overriding the default props inside the custom component?
from material-ui.
this would work of course, but i am not defining a custom component in that way, but simply using styled:
export const MyButton = styled(Button, {name: "MyButton", slot: "root"})({})
from material-ui.
Got it, Thanks for clarifying.
I'd say the styled components are for defining the styles.
But your idea of using prop overrides for creating new components is actually interesting. Let's wait for the thoughts from the maintainers.
from material-ui.
i see ... i thought that was the whole point of it :D
thanks for the reply
from material-ui.
As of right now, it's not supported the way you are expecting. We could probably add a way to override default props through the second argument of styled -
const MyButton = styled(Button, {
defaultProps: {
// new props
}
})()
But I'd say this would be least on our priorities right now.
@DiegoAndai Your thoughts ?
from material-ui.
thanks for evaluating this suggestion. indeed i can wrap the styled component around a functional one for now, but i just wanted a more elegant solution.
i think it would be enough to make this point more explicit from the documentation, in fact i am still wondering what can be overriden within the theme for themed styled component. i am assuming that only the "stylesOverride" part of the theme has an impact on the themed styled component, but again, that is just my assumption. i guess it would be great if the doc clearly states that, so no misambiguity arise.
btw FYI what i am trying to achieve here is the following:
- every user of my app has the ability to upload a logo picture
- the app loads a different MUI theme per each user
- the link to the logo is defined as a MyCustomCardMedia.defaultProps.image attribute of the theme
for now i use stylesOverride, but just wanted to know whether i could achieve that with defaultProps, which seems not to be the case.
cheers
from material-ui.
We could probably add a way to override default props through the second argument of styled
I'm not sure about this API, seems like we would be coupling the styled call with business logic.
@dberardo-com reading your use case, I think it would be better to decouple your logic from the theme. Instead of using the theme's default props, why not create a separate context in which the logo link is propagated, and then the component can read from it?
from material-ui.
i would love to use MUITheme because it has a pre-defined and pre-documented structure, so it is much easier to adopt and more robust.
from material-ui.
Related Issues (20)
- Support for enabling checkboxes only for leaf nodes
- [docs][pigment-css] Add opt-in migration to Pigment CSS
- [material-ui][Text FIeld] Outlined variant label is broken
- [docs] Material Icon Imports wrong in docs
- [joy-ui][Tooltip] Not working with custom sub-components
- [material-ui][Select] Cycle On Focus Without Having Options Open
- [material-ui][TablePagination] TablePagination component throws `You have provided an out-of-range value `4` for the select component.` warning HOT 1
- Using material ui styles with remix v2
- {...other} would overwrites the ownerState
- [RFC] Any Roadmaps or Plans for fully support for Next.js App Router and Server Components?
- [docs] Change dark theme component background color without affecting other states
- [core] Adopt eslint-plugin-react-compiler
- Textfield add autoSelect prop HOT 1
- When trying to link an application using MUI v5, application gets "TypeError: Cannot read properties of null (reading 'useContext')"
- can't set drawer root element HOT 1
- Footer pagination moves when appear / disappear the vertical scrollbar HOT 1
- [material-ui][Rating] Screen reader announces incorrect value for maximum amount of stars
- [core] Fix eslint-plugin-react-compiler issues HOT 8
- Issue with JAWS on DateTimePicker component v5.0.20
- Maps autocomplete example documentation incomplete
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from material-ui.