栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用样式组件覆盖ExpansionPanelSummary深层元素?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用样式组件覆盖ExpansionPanelSummary深层元素?

这个困难与使用样式化组件无关,而仅与包装

ExpansionPanelSummary
在另一个组件中有关。

您可以使用以下包装方式类似地重现此内容

ExpansionPanelSummary

const MyCustomSummary = props => {  return (    <ExpansionPanelSummary {...props} expandIcon={<ExpandMoreIcon />}>      <Typography>{props.text}</Typography>    </ExpansionPanelSummary>  );};

有几个类似的组件组,其中Material-
UI父组件会查找特定类型的子组件,并特别对待该子组件。例如,您可以在

ExpansionPanel

      if (isMuiElement(child, ['ExpansionPanelSummary'])) {        summary = React.cloneElement(child, {          disabled,          expanded,          onChange: this.handleChange,        });        return null;      }

幸运的是,Material-UI通过一种简单的方法可以通过

muiName
属性告诉您的自定义组件与特定的Material-UI组件相同:

MyCustomSummary.muiName = "ExpansionPanelSummary";

或者您的情况如下所示:

export const ExpansionPanelSummary = styled(props => (  <MUIExpansionPanelSummary    {...props}  />))``;ExpansionPanelSummary.muiName = "ExpansionPanelSummary";



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/616479.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号