React Admin输入组件始终为helperText添加一些额外的空间

问题描述 投票:0回答:1

最近,React Admin输入组件开始在下面添加额外的空间,以显示helperText(如果提供)。但是似乎无法通过建议添加helperText={false}来避免这种行为,例如:]]

<TextInput source="myField" helperText={false} />

无论我是否将[false]作为值传递给heplerText道具,它总是显示一些额外的空间。

我现在正在使用React Admin 3.2.3版本。

在RA的TextInput组件中,我们可以看到以下代码:

        helperText={ // <-- goes to MUI TextField
            <InputHelperText
                touched={touched}
                error={error}
                helperText={helperText} // <-- goes to RA InputHelperText
            />
        }

如果InputHelperText组件的helperText属性值等于false,则InputHelperText不渲染任何内容(在其渲染函数中返回null)。但是,即使我传递了“ false”,传递给基础MaterialUI heplerTextTextField属性的值也永远不会为null或未定义:它始终是InputHelperText组件,它可能会或可能不会呈现某些内容。

MaterialUI TextField组件依次分析其heplerText属性:

  const helperTextId = helperText && id ? `${id}-helper-text` : undefined; // <-- helperText from TextInput

  ...

  {helperText && (
    <FormHelperText id={helperTextId} {...FormHelperTextProps}>
      {helperText}
    </FormHelperText>
  )}

由于helperText永远不会为null或未定义,它将始终呈现FormHelperText,也许带有空的helperText

如果我这样更改RA TextInput组件的代码:

        helperText={helperText && touched && error ?
            <InputHelperText
              touched={touched}
              error={error}
              helperText={helperText}
            /> : null

一切正常,因为helperText组件的TextField属性的值等于false,所以TextInput的值(传递给基础MUI helperText的值)的确为空,因此不添加额外的空间。

我是否缺少某些东西,或者确实是一个错误?

最近,React Admin输入组件开始在下面添加额外的空间,以显示helperText(如果提供)。但是似乎无法通过添加helperText = {......>

material-ui react-admin
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.