代码之家  ›  专栏  ›  技术社区  ›  user944513

如何在选择框中添加禁用选项或默认选项?

  •  0
  • user944513  · 技术社区  · 8 年前

    select 组件。我想添加第一个禁用选项,比如请选择项目

    像这样用html实现

    <select name="tagging">
            <option selected disabled>I'm working</option>
            <option value="Option B">Option B</option>
            <option value="Option C">Option C</option>
    </select>
    

    我将如何实现这一点使用材料+反应

    这是我的密码 https://codesandbox.io/s/6836mkjx3

    <FormControl className={classes.formControl}>
                <InputLabel htmlFor="searchCriteria">SEARCH CRITERIA *</InputLabel>
                <Select
                  value={searchCriteria}
                  onChange={event => handleInput(event, "searchCriteria")}
                  input={<Input name="searchCriteria" id="searchCriteria" />}
                >
                  <MenuItem value={10}>Ten</MenuItem>
                  <MenuItem value={20}>Twenty</MenuItem>
                  <MenuItem value={30}>Thirty</MenuItem>
                </Select>
                <FormHelperText>Some important helper text</FormHelperText>
              </FormControl>
    

    https://material-ui.com/demos/selects/

    3 回复  |  直到 8 年前
        1
  •  0
  •   Andy Theos    8 年前

    你可以用

    <MenuItem value="">
      <em>None</em>
    </MenuItem>
    

    对于标准材料,选择 <option value="" /> 另外,您可以添加 disabled 道具。

    Codesandbox example forked from material-ui docs

        2
  •  2
  •   Lakshaya Sood    8 年前

    https://material-ui.com/demos/selects/#selects 这就是你要找的 示例在MaterialUI文档中给出 enter image description here

        3
  •  0
  •   Amruth    8 年前

    使用 value=""

    <MenuItem selected disabled value="">
         <em>None</em>
    </MenuItem>