Material ui textField 边框未完全显示
我使用材质 UI textField 标签,我想删除文本字段的标签,但是当我删除或什至将标签设置为 null 时,它不起作用,并且我错过了该标签的边框顶部
<Box
component="form"
sx={{
"& .MuiTextField-root": {
m: 0.2,
width: "100%",
marginBottom: "30px",
},
}}
noValidate
autoComplete="off"
>
<div>
<div className="pass-box">
<label>username</label>
</div>
<TextField
fullWidth
placeholder="username
label=""
id="outlined-size-small-1"
size="small"
value={username}
onChange={(e) => setUsername(e.target.value)}
InputProps={{
endAdornment: (
<IconButton className="log-icon">
<AccountCircleIcon />
</IconButton>
),
}}
></TextField>
<br />
<TextField
fullWidth
placeholder="password
label=""
type="password"
id="outlined-size-small"
size="small"
onChange={(e) => setPassword(e.target.value)}
InputProps={{
endAdornment: (
<IconButton className="log-icon">
<LockIcon />
</IconButton>
),
}}
></TextField>
<br />
</div>
</Box>
这是我的文本字段的图像,您会看到顶部边框丢失了
I use material UI textField tag and I want to remove the label of text field but when I remove or even set null my label it doesn't work, and I miss the border-top of that
<Box
component="form"
sx={{
"& .MuiTextField-root": {
m: 0.2,
width: "100%",
marginBottom: "30px",
},
}}
noValidate
autoComplete="off"
>
<div>
<div className="pass-box">
<label>username</label>
</div>
<TextField
fullWidth
placeholder="username
label=""
id="outlined-size-small-1"
size="small"
value={username}
onChange={(e) => setUsername(e.target.value)}
InputProps={{
endAdornment: (
<IconButton className="log-icon">
<AccountCircleIcon />
</IconButton>
),
}}
></TextField>
<br />
<TextField
fullWidth
placeholder="password
label=""
type="password"
id="outlined-size-small"
size="small"
onChange={(e) => setPassword(e.target.value)}
InputProps={{
endAdornment: (
<IconButton className="log-icon">
<LockIcon />
</IconButton>
),
}}
></TextField>
<br />
</div>
</Box>
this is an image of my text field and you see the border-top missed
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要删除文本字段的标签,您可以通过两种方式来实现。
解决方案 1。 -
只需将 InputLabelProps={{shrink: false}} 属性添加到 TextField 即可。
<文本字段
InputLabelProps={{收缩: false}}
...
>>
解决方案 2. - 添加 css 以删除 TextField 的图例。
"& .MuiOutlinedInput-notchedOutline 图例": {
显示:“无”,
}
To remove label of text field you can achieve this by two way.
Solution 1. -
Just add InputLabelProps={{shrink: false}} property to TextField.
<TextField
InputLabelProps={{shrink: false}}
...
/>
Solution 2. -Add css to remove legend of TextField.
"& .MuiOutlinedInput-notchedOutline legend": {
display: "none",
}
这里同样的问题!通过禁用 Boostrap css 解决。
MUI 提供了自己的类似 Bootstrap 的网格系统,所以它可能是
一个解决方案。
Same problem here! Solved with disabling Boostrap css.
MUI provides its own Bootstrap-like grid system, so it might be
a solution.
我通过更改 MuiOutlinedInput 和 MuiInputLabel 的主题默认属性解决了这个问题:
您可以阅读有关 MUI 组件重写的内容 此处。
I solved it by changing the theme default props of MuiOutlinedInput and MuiInputLabel like that:
You can read about MUI component overriding here.