“outlined”在 Material UI Select 中不起作用

'outlined' not working in Material UI Select

提问人:Lara 提问时间:12/10/2019 最后编辑:Lara 更新时间:8/6/2023 访问量:9437

问:

我正在实现 Material UI“Select”,其值来自后端。以下是我的代码

<FormControl variant="outlined" className={classes.formControl}>
  <InputLabel ref={inputLabel} id="demo-simple-select-outlined-label" htmlFor="outlined-Name">
                                    Name
  </InputLabel>
  <Select
    value={Name}
    onChange={handleChange}
    labelWidth={labelWidth}
    inputProps={{
      name: 'Name',
      id: 'outlined-Name',
   }}
>
 <MenuItem value="1" className={classes.menuItm}>All</MenuItem>
   {
     NameArr.data.map(Name => (
     <MenuItem value={Name.name} className={classes.menuItm}>{Name.name}</MenuItem>
 ))
   }
</Select>      
</FormControl>

以下代码的问题是未应用。我无法看到根据此处的演示应该存在的轮廓/边框 https://codesandbox.io/s/material-demo-9jyoj 我的代码中有什么问题?variant="outlined"

css reactjs select 下拉菜单 material-design

评论

1赞 Awais 12/10/2019
我不是 react 的专业人士,我正在使用 angular,但似乎您的代码在错误的地方使用,应该在他们的文档 material-ui.com/components/text-fields 中提到。因为使用它没有设置样式,因为它跳过了样式层次结构variant="outlined"<TextField<FormControl
0赞 Ido 12/10/2019
您的代码没问题,已应用概述。codesandbox.io/s/......

答:

0赞 meandre 2/3/2020 #1

您需要更新包。 在当前版本中,() 被正确地传递给子项。@material-ui/core4.9.1outlined<FormControl>

就我个人而言,从更新以修复此问题。4.1.04.9.1

0赞 Amir Rezvani 6/5/2021 #2

您应该应用大纲变体来选择,如下所示:

<FormControl className={classes.formControl}>
  <InputLabel ref={inputLabel} id="demo-simple-select-outlined-label" htmlFor="outlined-Name">
                                    Name
  </InputLabel>
  <Select
    value={Name}
    variant="outlined"    {/*  -------------> here is what you looking for */}
    onChange={handleChange}
    labelWidth={labelWidth}
    inputProps={{
      name: 'Name',
      id: 'outlined-Name',
   }}
>
 {NameArr.data.map(Name => (
     <MenuItem value={Name.name} className={classes.menuItm}>{Name.name}} 
     </MenuItem>
  )}
</Select>      
</FormControl>