我有一个自定义主题,我已经添加自定义颜色到调色板。我希望这个颜色道具能与定制的颜色搭配使用。我测试了Button组件,它工作得很好。但是,当我尝试对芯片组件执行相同的操作时,我收到了一个TypeScript错误:
TypeError: Cannot read properties of undefined (reading 'type')这就是我的主题:
const theme = createTheme({
palette: {
slate: {
darker: "#11161A",
dark: "#1F2932",
main: "#2E3D49",
light: "#6D7780",
lighter: "#B4B9BD",
lightest: "#F7F7F8",
}
}
});
export default theme;
declare module "@mui/material/styles" {
interface PaletteColor {
lightest?: string;
lighter?: string;
darker?: string;
}
interface PaletteOptions {
slate: any;
}
}
declare module "@mui/material/Button" {
interface ButtonPropsColorOverrides {
slate: true;
}
}
declare module "@mui/material/Chip" {
interface ChipPropsColorOverrides {
slate: true;
}
}还有想法呢?
发布于 2021-10-27 15:22:37
您的自定义颜色中缺少contrastText。在source中,当Chip颜色不是default时,它使用theme.palette[chipColorProp].main作为背景色,使用theme.palette[chipColorProp].contrastText作为前景色:
const theme = createTheme({
palette: {
slate: {
darker: '#11161A',
dark: '#1F2932',
main: '#2E3D49',
light: '#6D7780',
lighter: '#B4B9BD',
lightest: '#F7F7F8',
contrastText: '#ffffff', // <------------------ Add this line to fix
},
},
});
https://stackoverflow.com/questions/69741212
复制相似问题