Cannot override global default style (Heading component)
See original GitHub issue🐛 Bug report
Hello, I want to override global default styles to HTML elements when extending the theme object, so that when I use the as
prop, the overridden default styles would be referenced correctly. For example:
// theme
const theme = extendTheme({
styles: {
global: {
h3: {
fontSize: "50px",
fontWeight: "300"
}
}
}
});
// usage
<Heading as="h3">Hello world</Heading>
The fontSize
and fontWeight
styles above are not applied, but when I add color
it works fine. I wasn’t sure if this is a bug or intentional implementation detail.
💻 Link to reproduction
🧐 Expected behavior
New fontSize
and fontWeight
styles to be correctly applied on h3
element when:
- Extending theme global styles
- Setting
as="h3"
on a Heading component
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Global css file won't override component css - Stack Overflow
Make sure your style tag within component has scoped attribute otherwise it'll override global styles.
Read more >Global CSS text styles to override default Pro element styles?
Is it possible to set global styles for elements like headings and paragraphs using style.css or another method, which can be overridden in ......
Read more >How to Override CSS Styles - W3docs
You can set individual styles in your global CSS file as !important overrides inline styles set directly on elements. Example of overriding CSS...
Read more >Global Styling with Material-UI Theme Overrides and Props
Learn how to use global CSS overrides and default props in a theme to customize all instances of a Material-UI component in a...
Read more >Advanced Usage - styled-components
Theming, refs, Security, Existing CSS, Tagged Template Literals, Server-Side Rendering and Style Objects.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a valid reason and issue. Using
<Heading as="h1">Lorem</Heading>
should yield a h1 element without any defaultsize
prop. Headings should remain consistent throughout a UI and only have different sizes, when explicitly defined, not the other way around… .I had even to go that far and disable <Heading/> in our project with the following Eslint rule:
The other alternative would be creating a custom
size
namedh1
, but then you’d have to double specify props<Heading as="h1" size="h1>
.Please reconsider this issue.
If you want to use the
Heading
component you need to customize theHeading
component on the theme.If you don’t want to do that, then use the
Text
component insteadSee updated codesandbox https://codesandbox.io/s/old-river-uwpql?file=/src/App.js