Material ui textField 边框未完全显示

发布于 2025-01-10 07:57:56 字数 2051 浏览 3 评论 0原文

我使用材质 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

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰之心 2025-01-17 07:57:56

要删除文本字段的标签,您可以通过两种方式来实现。

解决方案 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",
}

难以启齿的温柔 2025-01-17 07:57:56

这里同样的问题!通过禁用 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.

高跟鞋的旋律 2025-01-17 07:57:56

我通过更改 MuiOutlinedInputMuiInputLabel 的主题默认属性解决了这个问题:

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

您可以阅读有关 MUI 组件重写的内容 此处

I solved it by changing the theme default props of MuiOutlinedInput and MuiInputLabel like that:

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

You can read about MUI component overriding here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文