在SelectDisplayProps
添加className实际上会覆盖其现有的className
我有一个成分。当我想给显示选择的选定值的div一个className时,而不是像每个材质ui组件一样将className添加到其他名称上,它会覆盖它们。
我有一个<Select />
组件,当我在SelectDisplayProps
添加className
时,它会覆盖该组件的现有className,这些类名会在。
它不应覆盖现有的className,而应将其添加到它们中。
在这里您可以找到一个沙箱来查看错误: https :
脚步:
SelectDisplayProps
实际上有一个对象:SelectDisplayProps={{
className: classes.selectDisplay
}}
SelectDisplayProps
更改为undefined,就像您未指定一个一样。SelectDisplayProps
,就存在材料UI默认类。 但是当指定了SelectDisplayProps
,className消失了我想覆盖显示选择值的元素的样式。 即使我完全改变了我要赋予的风格,问题仍然存在,所以我认为这无关紧要。
| 技术| 版本|
| ----------- | ------- |
| Material-UI | v4.11.0 |
| 反应| 16.13.1 |
| 浏览器| Chrome-版本86.0.4240.75(正式版本)(64位)|
| 打字稿| 3.9.5 |
@Newpoki感谢您的报告,我可以确认问题。 您如何看待此修复程序?
diff --git a/packages/material-ui/src/Select/SelectInput.js b/packages/material-ui/src/Select/SelectInput.js
index eb58ecd1b3..2098d0f3b8 100644
--- a/packages/material-ui/src/Select/SelectInput.js
+++ b/packages/material-ui/src/Select/SelectInput.js
@@ -353,16 +353,6 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
return (
<React.Fragment>
<div
- className={clsx(
- classes.root, // TODO v5: merge root and select
- classes.select,
- classes.selectMenu,
- classes[variant],
- {
- [classes.disabled]: disabled,
- },
- className,
- )}
ref={setDisplayNode}
tabIndex={tabIndex}
role="button"
@@ -376,6 +366,17 @@ const SelectInput = React.forwardRef(function SelectInput(props, ref) {
onBlur={handleBlur}
onFocus={onFocus}
{...SelectDisplayProps}
+ className={clsx(
+ classes.root, // TODO v5: merge root and select
+ classes.select,
+ classes.selectMenu,
+ classes[variant],
+ {
+ [classes.disabled]: disabled,
+ },
+ className,
+ SelectDisplayProps.className
+ )}
// The id is required for proper a11y
id={buttonId}
>
您要处理请求吗? :)
我想尝试一下。 你能把它分配给我吗?
你好,
抱歉,我的答复很晚,我在工作:sweat_smile:
很高兴这是一个真实的问题,不是我的想法,它将得到解决:D
感谢@reedanders的公关。