【问题标题】:Overriding with classes in material-ui v1.0.0-beta-1 shows "the key provided to the classes property is not implemented" warning用 material-ui v1.0.0-beta-1 中的类覆盖显示“提供给类属性的键未实现”警告
【发布时间】:2017-12-30 06:37:33
【问题描述】:

我正在尝试使用 overriding by classes 方法覆盖 Material-UI v1 组件的样式。

当我尝试覆盖嵌套属性时,例如 root 键上的 :hover 伪类,我收到以下警告:

Warning: Material-UI: the key `.MyButton-root-w:hover` provided to
the classes property object is not implemented in Button.
You can only overrides one of the following: 

参见示例:

import React from "react";
import { createStyleSheet, withStyles } from "material-ui/styles";
import Button from "material-ui/Button";

const buttonStyle = createStyleSheet("MyButton", {
  root: {
    backgroundColor: "#f99",
    "&:hover": {
      backgroundColor: "#99f"
    }
  }
});

export default withStyles(buttonStyle)(Button);

或者在https://codesandbox.io/s/gRgGrYvr查看它的实际应用

由于示例按钮在悬停时确实会获得不同的背景颜色,我想知道这是否是 Material-UI 中的问题,或者我还没有完全掌握如何覆盖其样式。

【问题讨论】:

    标签: reactjs material-ui


    【解决方案1】:

    感谢@kybarg 在Material-UI's Gitter 上帮助我,我知道如何解决这个问题,请参阅他为帮助我而制作的CodeSandbox

    出现警告是因为根键旁边的 classes 属性还包含一个 .MyButton-root-p:hover 属性,而 Button显然不支持该属性。要解决这个问题,请确保您只将支持的键传递给 Button,例如:

    export default withStyles(buttonStyle)(({ classes, ...restProps}) => (
      <Button classes={{ root: classes.root }} {...restProps} />
    ));
    

    【讨论】:

    • 你如何确保它与 react/typescript 一起工作?我在使用 Material UI 纸张时遇到了同样的错误,目前尚不清楚如何修复它。查看我的完整代码:gist.github.com/daneasterman/cc8e9ebe58c60d825f8f3762c572cf91
    • 抱歉,完整的错误是:Material-UI:提供给 classes 属性对象的键 .Component-root-199:hover 未在 Paper 中实现。您只能覆盖以下之一:root,rounded,shadow0,shadow1,shadow2,shadow3,shadow4,shadow5,shadow6,shadow7,shadow8,shadow9,shadow10,shadow11,shadow12,shadow13,shadow14,shadow15,shadow16,shadow17,shadow18 ,shadow19,shadow20,shadow21,shadow22,shadow23,shadow24
    猜你喜欢
    • 2018-08-02
    • 2019-11-10
    • 2021-03-02
    • 1970-01-01
    • 2021-01-17
    • 2020-09-08
    • 2018-05-27
    • 2021-05-16
    • 2018-05-11
    相关资源
    最近更新 更多