Rom*_*nas 7 css reactjs material-ui next.js
我正在尝试创建我自己的主题Material-Ui v.5.4.0。我遇到了问题。我无法更改TextField focused边框color和width. 我花了几个小时进行研究,但没有找到可行的解决方案。我开始思考是否有可能在主题中做到这一点?但这不符合逻辑。
我当前的主题代码:
import { createTheme } from '@mui/material/styles'
// Colors
const blue = '#5A5BD4'
const blueDark = '#4f4fd8'
// Parameters
const buttonsBorderRadius = 20
const buttonPadding = '5px 15px'
const inputBorderRadius = 10
const theme = createTheme({
components: {
// Buttons
MuiButton: {
variants: [
// Blue button
{
props: { variant: 'blueButton' },
style: {
backgroundColor: blue,
color: '#ffffff',
borderRadius: buttonsBorderRadius,
textTransform: 'none',
padding: buttonPadding,
'&:hover': {
backgroundColor: blueDark
}
}
},
// Transparent button
{
props: { variant: 'transparentButton' },
style: {
color: blue,
borderRadius: buttonsBorderRadius,
textTransform: 'none',
padding: buttonPadding
}
}
]
},
// Inputs
MuiOutlinedInput: {
styleOverrides: {
root: {
borderRadius: inputBorderRadius,
'& fieldset': {
border: `1px solid ${blue}`
}
},
focus: {
border: `1px solid ${blueDark}`
}
}
}
}
})
export default theme
Run Code Online (Sandbox Code Playgroud)
我的输入代码:
<TextField
size='small'
variant='outlined'
label={t('paslelbimo_data_nuo')}
type='date'
InputLabelProps={{
shrink: true
}}
fullWidth
value={publicationDateFrom}
onChange={(e) => setPublicationDateFrom(e.target.value)}
/>
Run Code Online (Sandbox Code Playgroud)
Ste*_*mez 13
由于我无法准确说出您想要的聚焦效果和非聚焦效果,因此我决定创建一个通用示例,其样式过于戏剧化,这可能有助于根据您的需求进行修改:
本质上,我只是覆盖.MuiOutlinedInput-notchedOutline聚焦和非聚焦状态:
const theme = createTheme({
components: {
// Inputs
MuiOutlinedInput: {
styleOverrides: {
root: {
...
"& .MuiOutlinedInput-notchedOutline": {
border: `5px solid green`,
},
"&.Mui-focused": {
"& .MuiOutlinedInput-notchedOutline": {
border: `5px dotted red`,
},
}
},
}
}
}
});
Run Code Online (Sandbox Code Playgroud)
工作示例 CodeSandbox:https://codesandbox.io/s/customstyles-material-demo-forked-uri26? file=/theme.js:84-531
| 归档时间: |
|
| 查看次数: |
4536 次 |
| 最近记录: |