MUI TextField 中的 inputProps 与 InputProps

inputProps vs InputProps in MUI TextField

<em><strong>i</strong></em>nputProps[=有什么区别18=]<strong>I</strong></em>nputProps?下面的 2 TextFields 做同样的事情。我什么时候必须二选一?

<TextField
  label="inputProps"
  inputProps={{
    name: 'inputProps',
    type: 'number',
    placeholder: 'placeholder',
    value,
    onChange: handleChange,
  }}
/>
<TextField
  label="InputProps"
  InputProps={{
    name: 'InputProps',
    type: 'number',
    placeholder: 'placeholder',
    value,
    onChange: handleChange,
  }}
/>

InputProps 适用于 Input react-component since:

TextField is composed of smaller components ( FormControl, Input, FilledInput, InputLabel, OutlinedInput, and FormHelperText ) that you can leverage directly to significantly customize your form inputs.

inputProps 适用于将成为 input DOM 元素的元素,它会获得其所有 attributes.

因此,如果需要更改与 input 作为 React 组件有关的某些内容(例如设置 Icon),我们应该使用 InputProps。对于不受 Input component properties there's a variety of input attributes.

控制的所有其他更改