概述的Material-UI主题覆盖

时间:2020-10-09 11:31:53

标签: reactjs material-ui

我有一个自定义theme,在其中我想覆盖border-color组件的OutlinedInput。任何人都知道如何覆盖focused颜色吗?

export const defaultTheme = createMuiTheme({
    palette: {
        primary: {
            main: colors.primary,
            contrastText: colors.white,
        },
        ...
    },
    typography: {
        ...
    },
    overrides: {
        MuiButton: {
            outlinedPrimary: {
                color: colors.text,
            },
        },
        MuiInput: {
          underline: {
            '&::before': {
              borderBottomColor: colors.grey,
            },
            '&::after': {
              borderBottomColor: colors.greyDark,
            }
          },
        },
        MuiOutlinedInput: {
          notchedOutline: {
            borderColor: colors.grey,
          },
        }
    }
});

1 个答案:

答案 0 :(得分:0)

找到了解决方案:

overrides: {
        MuiButton: {
            outlinedPrimary: {
                color: colors.text,
            },
        },
        MuiInput: {
          underline: {
            '&::before': {
              borderBottomColor: colors.grey,
            },
            '&::after': {
              borderBottomColor: colors.greyDark,
            }
          },
        },
        MuiOutlinedInput: {
          root: {
            '&$focused': {
              '& $notchedOutline': {
                borderColor: colors.greyDark,
              },
            },
          },
          notchedOutline: {
            borderColor: colors.grey,
          },
        }
    }