简体   繁体   English

material ui textField 边框没有完全显示

[英]material ui textField border doesn't show completely

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我使用材料 UI textField 标签,我想删除文本字段的 label 但是当我删除甚至设置 null 我的 label 它不起作用,我错过了它的边框顶部

 <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这是我的文本字段的图像,您会看到 border-top missed

在此处输入图像描述

Same problem here!这里同样的问题! Solved with disabling Boostrap css.通过禁用Boostrap css 解决。

MUI provides its own Bootstrap-like grid system, so it might be a solution. MUI 提供了自己的类似 Bootstrap 的网格系统,因此它可能是一个解决方案。

To remove label of text field you can achieve this by two way.要删除文本字段的标签,您可以通过两种方式实现此目的。

Solution 1. - Just add InputLabelProps={{shrink: false}} property to TextField.解决方案 1. - 只需将 InputLabelProps={{shrink: false}} 属性添加到 TextField。

<TextField InputLabelProps={{shrink: false}} ... /> <TextField InputLabelProps={{shrink: false}} ... />

Solution 2. -Add css to remove legend of TextField.解决方案 2. - 添加 css 以删除 TextField 的图例。

"& .MuiOutlinedInput-notchedOutline legend": { display: "none", } "& .MuiOutlinedInput-notchedOutline 图例": { display: "none", }

I solved it by changing the theme default props of MuiOutlinedInput and MuiInputLabel like that:我通过像这样更改MuiOutlinedInputMuiInputLabel的主题默认道具来解决它:

const theme = createTheme({
  components: {
    MuiOutlinedInput: {
      defaultProps: {
        notched: false,
      },
    },
    MuiInputLabel: {
      defaultProps: {
       shrink: false,
      },
    }
  },
});

You can read about MUI component overriding here .您可以在此处阅读有关 MUI 组件覆盖的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM