javascript - Material-UI组件中componentsProps的用途是什么?
问题描述
我在 , , 等组件的 API 文档中看到了这一点。我componentsProps
没有得到任何最好的例子和完美的 prop 定义。AutoComplete
StepLabel
BackDrop
任何人都请用简单的基本和简单的例子来解释它何时,为什么以及如何使用它!
解决方案
MUI 暴露componentsProps
在一些组件上,让你覆盖内部组件的 props。具体来说:
在
Autocomplete
组件中,它用于覆盖AutocompleteClearIndicator
props。在
StepLabel
中,它用于覆盖标签组件(不包括图标)。另请注意,API 并不像@Drew Reese指出的那样不一致,您只能用 覆盖标签道具componentsProps
,但要覆盖图标道具,您必须改用StepIconProps
道具。在其他一些组件中,例如
Menu
,没有componentsProp
butTransitionProps
和MenuListProps
props 可以单独覆盖内部的组件。
不幸的是,因为那里的道具是无类型的(都标记为object
),并且文档中的其他任何地方都没有提及。您必须深入研究源代码才能了解componentsProps
特定组件中的功能。
下面是Autocomplete
移除了 clear 指示符的组件示例。请注意,您可以使用disableClearable
in来执行此操作Autocomplete
,这只是一个示例,用于演示如何componentsProp
潜在地有用:
<Autocomplete
componentsProps={{
clearIndicator: {
sx: {
display: "none"
}
}
}}
options={top100Films}
sx={{ width: 300 }}
renderInput={(params) => <TextField {...params} label="Movie" />}
/>
推荐阅读
- excel - Excel VBA 更新链接
- json - 使字符串同时有效 JSON 和 shell 转义
- tensorflow - 在tensorflow中,如何枚举训练数据(对比pytorch)
- javascript - 如何在 node.js sequelize 中使用 varchar?
- java - Docker&Java:构建不反映新文件
- google-apps-script - 是否可以从谷歌表中隐藏谷歌脚本?
- c# - Polly - 请在调用异步 ExecuteAsync(和类似)方法时使用异步定义的策略
- python - 制作石头剪刀布游戏时的值错误
- php - WordPress 类别搜索简码不显示选项
- r - R ggplot2 TCGA 表达数据的分组箱线图