最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Overriding Material-UI Select Style - Stack Overflow

programmeradmin3浏览0评论

I am trying to override the styling applied by Material-UI's <Select> ponent when variant="outlined". For this example, I want the <Select>'s dropdown icon to be hidden and padding-right to be 0px.

From my understanding of the API, I should be able to overwrite the styles by passing in classes={{ icon: classes.hideIcon, outlined: classes.noPaddingRight }}, where classes is:

const useStyles = makeStyles(theme => ({
  hideIcon: {
    display: "none"
  },
  noPaddingRight: {
    paddingRight: "0px"
  }
}));
const classes = useStyles();

I am able to successfully hide the icon, but my noPaddingRight class is overridden by both MuiSelect-select.MuiSelect-select and MuiSelect-outlined.MuiSelect-outlined (I'm also confused what the . is doing in those two classes):

The only way I've gotten it to work is by using paddingRight: 0px !important but that's something I'd like to avoid if at all possible.

Here is the CodeSandbox:

I am trying to override the styling applied by Material-UI's <Select> ponent when variant="outlined". For this example, I want the <Select>'s dropdown icon to be hidden and padding-right to be 0px.

From my understanding of the API, I should be able to overwrite the styles by passing in classes={{ icon: classes.hideIcon, outlined: classes.noPaddingRight }}, where classes is:

const useStyles = makeStyles(theme => ({
  hideIcon: {
    display: "none"
  },
  noPaddingRight: {
    paddingRight: "0px"
  }
}));
const classes = useStyles();

I am able to successfully hide the icon, but my noPaddingRight class is overridden by both MuiSelect-select.MuiSelect-select and MuiSelect-outlined.MuiSelect-outlined (I'm also confused what the . is doing in those two classes):

The only way I've gotten it to work is by using paddingRight: 0px !important but that's something I'd like to avoid if at all possible.

Here is the CodeSandbox: https://codesandbox.io/s/overwrite-select-style-zqk1r

Share Improve this question asked Apr 27, 2020 at 4:48 andyrooandyroo 1571 gold badge2 silver badges8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 12

You can use nesting selector for the className MuiSelect-outlined

hideIconPadding: {
  "& .MuiSelect-outlined": {
    paddingRight: "0px"
  }
}

Notice that use className here:

className={classes.hideIconPadding}

发布评论

评论列表(0)

  1. 暂无评论