Input style props not being overwritten with customized theme
See original GitHub issueCustom theme API for components.Input
not working
Describe the bug
Input styles are not being overwritten when using the customize theme API: https://next.chakra-ui.com/docs/theming/customize-theme
To reproduce
customize your theme:
const Input = {
baseStyle: {
borderColor: 'primary.accent2',
_hover: {
borderColor: 'primary.foreground',
},
},
sizes: {
sm: {
fontSize: 'md',
height: '40px',
}
},
defaultProps: {
size: 'sm',
},
}
const theme = extendTheme({
components: {
Input,
}
})
use this input:
import { Input } from '@chakraui/core'
const Component = props => <Input />
Expected behavior
The default exported input should adopt custom theme styles
Additional context
This API and method works with the Button component (theme.components.Button
). With Input
, however, no styles seem to render. They don’t seem to exist in the DOM at all.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:24 (3 by maintainers)
Top Results From Across the Web
How can I overwrite styles of an autofilled input when using ...
If I understand correctly, the reason that Input background styles are not applied via baseStyles is that styles for ...
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 >How to customize - Material UI - MUI
Material UI provides several different ways to customize a component's styles. Your specific context will determine which one is ideal.
Read more >Customize Theme - Chakra UI
The properties in sizes of the component will be overwritten if passed in the responsive variant. With responsive variants, prop override might not...
Read more >4 Ways to Override Material UI Styles | by John Au-Yeung
Material UI offers more than just a single way to override its styling. That's great for us but it can also be very...
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
Okay I did a deep dive. Hope this is helpful to anyone else who comes along.
baseStyle.field
and not justbaseStyle
baseStyle
styles are overridden bysizes
styles (borderRadius, fontSize, height & padding) as well asvariant
styles (background, border, borderColor, _focus, _hover and sometimes others.)variant
styles will override allsizes
styles.defaultProps.size
and/ordefaultProps.variant
tonull
will remove those styles. I don’t love this solution because it remove all styles, and I don’t want to have to re-set everything because I wanted a different background color.The simplest way to make a basic change, like to a background or border, would be to set it on the variant that you’re using:
Here’s a component (err, component style object) that shows all defaults.
Setting
variant
to null indefaultProps
works too!