Material-UI 需要输入密码

Material-UI password input required

使用 MUI @Next 和 TextField 组件。

当您将 required 作为道具添加时,

MUI 非常漂亮地在标签末尾添加了一点 *,但是当您添加endAdornment 以启用 "show password" 切换。

我创建了a codesandbox of my issue

常规 <Texfield /> 组件按预期显示 *,但同样需要的密码字段没有显示。

在对我的问题进行 codesandbox 重现时,我找到了答案,但我想我会把它留在这里供遇到此问题的其他人使用。 required 道具必须在输入的 <FormControl /> 包装器上继续:

<FormControl required ... >
   <InputLabel ... >Password</InputLabel>
   <Input ... />
</FormControl>