[英]how to remove border in textfield fieldset in material ui
I need to remove the border.我需要删除边框。 I used some css from stack overflow but the issue is not fixed yet.
我从堆栈溢出中使用了一些 css,但问题尚未解决。 If any one please help me to fixed this issue.I shall be very thank full.
如果有人请帮我解决这个问题。我将非常感谢。
what css I write to remove the border.我写什么 css 去掉边框。
<TextField variant="outlined" margin="normal" required fullWidth id="phoneNumber" disableUnderline={false} // label="Phone Number" name="phoneNumber" autoComplete="phoneNumber" autoFocus onChange={handlePhoneNumberChange} className={classes.textField} placeholder="Phone Number" InputProps={{ startAdornment: ( <InputAdornment position="start"> <AccountCircle /> </InputAdornment> ), }} />
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.1.1/umd/react.production.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.1.1/umd/react-dom.production.min.js"></script>
I was looking for a borderless text-field and this is working for me...我正在寻找一个无边界的文本字段,这对我有用......
<TextField
variant="standard" // <== changed this
margin="normal"
required
fullWidth
id="phoneNumber"
name="phoneNumber"
autoComplete="phoneNumber"
autoFocus
onChange={handlePhoneNumberChange}
placeholder="Phone Number"
InputProps={{
startAdornment: <AccountCircle />, // <== adjusted this
disableUnderline: true, // <== added this
}}
/>
These 2 props seem to be the key...这2个道具似乎是关键......
variant="standard"
InputProps={{
disableUnderline: true,
}}
InputProps
can be passed to the style the variants of the inputs. InputProps
可以传递给样式输入的变体。 For outlined
input there a class named .MuiOutlinedInput-notchedOutline
which sets the border in this question's case.对于
outlined
的输入,有一个名为.MuiOutlinedInput-notchedOutline
,它在这个问题的情况下设置了边界。 To modify this class, pass the styles to the notchedOutline
prop in InputProps
.要修改此 class,请将 styles 传递给 InputProps 中的
notchedOutline
InputProps
。
const useStyles = makeStyles(() => ({
noBorder: {
border: "none",
},
}));
const TextInput = props => {
const { onChange, type} = props;
const classes = useStyles();
return (
<TextField
variant="outlined"
margin="normal"
required
fullWidth
id="phoneNumber"
disableUnderline={false}
// label="Phone Number"
name="phoneNumber"
autoComplete="phoneNumber"
autoFocus
classes={{notchedOutline:classes.input}}
// onChange={handlePhoneNumberChange}
className={classes.textField}
placeholder="Phone Number"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
classes:{notchedOutline:classes.noBorder}
}}
/>
);
};
Here is the working sandbox link: https://codesandbox.io/s/material-demo-forked-nhlde这是工作沙箱链接: https://codesandbox.io/s/material-demo-forked-nhlde
In your textField style add outline: 'none'
在您的 textField 样式中添加
outline: 'none'
I tried all the answers here.我在这里尝试了所有答案。
Doesn't work不工作
I found this InputBase It works very nicely.我发现这个InputBase非常好用。 This is exactly what you should use.
这正是您应该使用的。
They have provided the sandbox too Sandbox InputBase他们也提供了沙箱Sandbox InputBase
As at 2022, if your using MUI >= version 5, you can use some solutions here, and currently there's no where in the doc on how do this in Textfield.截至 2022 年,如果您使用 MUI >= 版本 5,您可以在此处使用一些解决方案,目前文档中没有关于如何在 Textfield 中执行此操作的位置。
Another nice component MUI provides is the Input, and luckily for us it accepts almost all props passed to Textfield, that's where you can do disableUnderline={false} and it will work as expected. MUI 提供的另一个不错的组件是 Input,幸运的是,它接受几乎所有传递给 Textfield 的道具,您可以在其中执行 disableUnderline={false} 并且它会按预期工作。
<Input
disableUnderline={true}
variant="standard"
autoFocus
onChange={yourChangeHandler}
value={value}
placeholder="Title"
fullWidth
/>
For Outlined TextField对于大纲文本字段
If you want to remove outlines from the outlined text field.如果要从带轮廓的文本字段中删除轮廓。 Then add this in your TextField
然后将其添加到您的 TextField
sx={{border: 'none',"& fieldset": { border: 'none' },}}
Here is your code...这是您的代码...
<TextField
variant="outlined"
sx={{border: 'none', "& fieldset": { border: 'none' },}}
margin="normal"
required
fullWidth
id="phoneNumber"
disableUnderline={false}
// label="Phone Number"
name="phoneNumber"
autoComplete="phoneNumber"
autoFocus
onChange={handlePhoneNumberChange}
className={classes.textField}
placeholder="Phone Number"
InputProps={{
startAdornment: (
<InputAdornment position="start">
<AccountCircle />
</InputAdornment>
),
}}
/>
For Standard TextField对于标准文本字段
If you want to remove underline from the standard text field.如果要从标准文本字段中删除下划线。 Then add this in your TextField
然后将其添加到您的 TextField
InputProps={{ disableUnderline: true }}
Here is code这是代码
<TextField
fullWidth
placeholder="Search..."
InputProps={{ disableUnderline: true }}
/>
Finally, the following css works (2022)最后,以下 css 工作(2022)
'& .MuiInput-root': {
'&:before, :after, :hover:not(.Mui-disabled):before': {
borderBottom: 0,
},
},
Try to override style尝试覆盖样式
See example below请参阅下面的示例
Added sx prop with below attributes in TextField and it worked fine for me在 TextField 中添加了具有以下属性的 sx 道具,它对我来说效果很好
<TextField
sx={{
input: {
border: "none",
},
"::placeholder": { color: "white" },
}}
/>
Just add只需添加
".MuiOutlinedInput-notchedOutline": { border: "none" },
to the sx prop.到 sx 道具。
This works both for MUI Select and Textfield这适用于 MUI Select 和 Textfield
The documentation doesn't offer any good way to do this该文档没有提供任何好的方法来做到这一点
So you can select the Mui
selector for that element and modify it directly所以你可以 select 该元素的
Mui
选择器并直接修改它
This worked for me.这对我有用。 You can override the css
您可以覆盖 css
<TextField
id="outlined-basic"
label="Outlined"
variant="outlined"
sx={{ "& .MuiOutlinedInput-notchedOutline": { border: "none" } }}
/>
<TextField
id="filled-basic"
label="Filled"
variant="filled"
sx={{
"& .MuiFilledInput-underline:before": {
borderBottom: "none",
},
"& .MuiFilledInput-underline:after": {
borderBottom: "none",
},
"& .MuiFilledInput-underline:hover:not(.Mui-disabled):before": {
borderBottom: "none",
},
}}
/>
https://codesandbox.io/s/fancy-shadow-515yoi?file=/src/App.js https://codesandbox.io/s/fancy-shadow-515yoi?file=/src/App.js
to remove border in TextField fieldset in MUI 5,在 MUI 5 中删除 TextField 字段集中的边框,
simply add following.只需添加以下内容。
sx={{
"& fieldset": { border: 'none' },
}}
If you want to remove the border for all MuiOutlinedInput components, add this to your theme's components
object:如果您想删除所有 MuiOutlinedInput 组件的边框,请将其添加到您的主题
components
object:
export const theme = createTheme({
// ...
components: {
// ...
MuiOutlinedInput: {
styleOverrides: {
notchedOutline: {
border: 'none',
},
},
},
},
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.