我希望在使用material-ui TextField时,去掉TextField下方的下划线。我知道可以使用material-ui的InputBase来实现这一点,但是我需要使用TextField API来实现,但在API指南中没有找到相应的方法。
<TextField
fullWidth
placeholder="Search..."
InputProps={{ disableUnderline: true }}
/>
InputProps
,并将其大写,这很有效。 - jstnnodisableUnderline
属性)。在写出有关如何自定义下划线的答案后,我错过了一个专门用于删除下划线的属性。
:before
来设置默认和悬停样式,使用:after
来设置焦点样式,因此需要删除这两种情况的边框。"&&&:before"
)可以增加CSS specificity规则的特异性,以便它胜过默认样式(例如&:hover:not($disabled):before
)。import React from "react";
import ReactDOM from "react-dom";
import TextField from "@material-ui/core/TextField";
import { makeStyles } from "@material-ui/core/styles";
const useStyles = makeStyles({
underline: {
"&&&:before": {
borderBottom: "none"
},
"&&:after": {
borderBottom: "none"
}
}
});
function App() {
const classes = useStyles();
return <TextField defaultValue="default text" InputProps={{ classes }} />;
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
variant
属性,它在文档中被标记为“裸输入”。 - Chris W.InputBase
(而不是TextField
)-- 这正是该问题所提到要避免的确切解决方案。 - Ryan Cogswell