【发布时间】:2020-04-18 07:20:01
【问题描述】:
我正在使用 Material UI 和 ThemeProvider 来覆盖一些样式,但是,被覆盖的样式正在影响我没有包含在 ThemeProvider 标签中的组件。另外,我不得不使用 !important 来覆盖某些样式,是否有原因它仍在使用默认样式而不是使用 !important 来覆盖我的覆盖样式?
我的代码如下。我只想覆盖下拉组件的样式,但 CreateNewFolder 组件也受到了影响。
const theme = createMuiTheme({
overrides: {
MuiOutlinedInput: {
input: {
padding: "8px 14px !important"
}
},
MuiInputLabel: {
formControl: {
transform: "none !important",
top: "-6px !important",
left: "45px !important",
backgroundColor: "white",
fontSize: "0.8rem",
padding: "0 6px"
}
},
MuiSelect: {
select: {
"&:focus": {
backgroundColor: "white"
}
}
}
}
});
return (
<>
<div
style={{
display: "flex",
justifyContent: "space-between",
padding: "25px 95px 15px 75px",
height: "10vh"
}}
>
<div>
<Button
variant="contained"
onClick={handleNewAdunit}
style={{ marginRight: "15px" }}
>
<AddIcon /> Adunit
</Button>
<Button onClick={handleFolder} variant="outlined">
<AddIcon /> Folder
</Button>
</div>
<div style={{ display: "flex", paddingLeft: "30px" }}>
<SearchBar
inputProps={{
value: "",
onChange: () => {},
style: {
width: "300px"
}
}}
results={[]}
displayKey={"component"}
/>
<ThemeProvider theme={theme}>
<Dropdown
label="Sort By"
variant="outlined"
onChange={() => {}}
menuItems={[
{
label: "Last modified",
key: "last modified"
},
{ label: "Option 2", key: "option 2" },
{ label: "Option 3", key: "option 3" }
]}
style={{
width: "150px",
marginLeft: "30px"
}}
/>
<Dropdown
label="Show"
variant="outlined"
onChange={() => {}}
menuItems={[
{ label: "My files", key: "my files" },
{ label: "Option 2", key: "option 2" },
{ label: "Option 3", key: "option 3" }
]}
style={{
width: "150px",
marginLeft: "30px"
// height: "35px"
}}
/>
</ThemeProvider>
</div>
</div>
<div>
<CreateNewFolder ref={folderRef} />
<Snackbar
ref={adunitRef}
variant="info"
message="Stay tuned. New feature coming soon!"
/>
</div>
</>
【问题讨论】:
标签: reactjs material-ui