网站搜索

reactjs - 如何在 material-ui 中自定义 DialogTitle


我正在学习 React 和 Material-UI,并尝试更新 DialogTitle 组件中字体的颜色。这个链接提供了通过重写 dialog 根类的解决方案(代码如下)。我如何重写 DialogTitle 的根类以便我可以更改标题的样式?

root: {
    backgroundColor: theme.palette.primary.main,
    '& h6': {
      color: 'red'
    }
  }

找到了解决方案。

<DialogTitle
    disableTypography
    id="alert-dialog-title"
    style={{ backgroundColor: 'navy', color: 'white' }}
>
    <Typography variant="h6">{ErrorBoundary.title}</Typography>
</DialogTitle>

答案#1

如果你想在你的 theme.js 文件中,或者在你主题所在的位置,覆盖 DialogTitle,你可以这样做:

MuiDialogTitle: {
  root: {
    color: 'blue'
  }
}

您必须提到组件类名。在每个 Material UI 组件的 API 部分,这里指定了名称: