javascript - What is the proper way to show blank menu item for SelectField (material-ui, react) - Stack Overflow

I use select-field from material-ui framework of latest 0.15.4 version with react of version 15.4.0. I

I use select-field from material-ui framework of latest 0.15.4 version with react of version 15.4.0. I try to add blank menu-item to select-field to be able to diselect value for 'dropdown' field when I click on it. When I try to add it in the way like

<MenuItem value="" primaryText="" />

it doesn't appear in the dropdown list of items. What is the proper way to add functionality of selection blank field in SelectField?

I use select-field from material-ui framework of latest 0.15.4 version with react of version 15.4.0. I try to add blank menu-item to select-field to be able to diselect value for 'dropdown' field when I click on it. When I try to add it in the way like

<MenuItem value="" primaryText="" />

it doesn't appear in the dropdown list of items. What is the proper way to add functionality of selection blank field in SelectField?

Share Improve this question asked Aug 18, 2016 at 7:41 yavalvasyavalvas 3302 silver badges17 bronze badges 1
  • Maybe you should use a Divider – Mario Santini Commented Aug 18, 2016 at 7:46
Add a ment  | 

1 Answer 1

Reset to default 5

setting the MenuItem value to "" and primaryText to "" will make it invisible in the choices.

I suggest you do this:

<SelectField value={this.state.some_key}>
    <MenuItem value="Choice1" primaryText="Choice1" />
    <MenuItem value="Select" primaryText="Select" />
</SelectField>

and then on onChange:

onChange = (event, index, value) => {
    if(value === "Select") {
        this.setState({some_key = ""})
    }
}

This will show blank input on the field once the "Select" is clicked.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744219514a4563711.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信