【问题标题】:How to change Material UI stepper background color if there is an error in a step如果步骤中有错误,如何更改 Material UI 步进器背景颜色
【发布时间】:2022-01-01 14:04:43
【问题描述】:

我正在使用 Material UI 的步进器组件,如果出现错误,我会尝试设置步进器的背景颜色。但是,不知道该怎么做。我能够为已完成的步骤设置背景颜色,并在此处完成:

【问题讨论】:

    标签: javascript css reactjs bootstrap-4 material-ui


    【解决方案1】:

    只需使用 lib 提供的 css 覆盖

    const useStyles = makeStyles(theme => ({ error: { ... } }))
    
    const MyComponent = props => {
        const [isError, setIsError] = useState(false);
        const classes = useStyles()
    
        // just apply a conditional class to the root to make the background
        // any color you want
        return <Stepper classes={{ root: isError ? classes.error : '' }}>
            ...
        </ Stepper>
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-01
      • 2021-08-01
      • 1970-01-01
      • 2022-01-02
      • 2019-04-12
      • 2017-03-28
      相关资源
      最近更新 更多