Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 如何在单击时打开React MaterialUI下拉列表?_Reactjs_Dropdown_Material Ui - Fatal编程技术网

Reactjs 如何在单击时打开React MaterialUI下拉列表?

Reactjs 如何在单击时打开React MaterialUI下拉列表?,reactjs,dropdown,material-ui,Reactjs,Dropdown,Material Ui,我有一个材质UI下拉组件和一个标签。如何单击标签打开此下拉列表 <label>Dash style</label> <DropDownMenu value={this.props.seriesOptions.dashStyle} onChange={this.handleDashChange} > <MenuItem key={1} value={"Solid"} label="Solid" primaryText="Solid"

我有一个材质UI下拉组件和一个标签。如何单击标签打开此下拉列表

<label>Dash style</label>
<DropDownMenu
    value={this.props.seriesOptions.dashStyle}
    onChange={this.handleDashChange} >
    <MenuItem key={1} value={"Solid"} label="Solid" primaryText="Solid" />
    <MenuItem key={2} value={"ShortDash"} label="ShortDash" primaryText="ShortDash" />
    <MenuItem key={3} value={"ShortDot"} label="ShortDot" primaryText="ShortDot" />
</DropDownMenu>
破折号样式

据我所知,
下拉菜单组件没有让您控制其状态的属性。但是,您可以使用
Popover
菜单组件来执行此操作

你可以这样写

        <label onClick={(event) => {
          this.setState({
            open: true,
            anchorEl: event.currentTarget,
          });
        }}>Dash style</label>
        <Popover
          open={this.state.open}
          anchorEl={this.state.anchorEl}
          anchorOrigin={{horizontal: 'left', vertical: 'bottom'}}
          targetOrigin={{horizontal: 'left', vertical: 'top'}}
          onRequestClose={this.handleRequestClose}
          animation={PopoverAnimationVertical}
        >
          <Menu
            value={this.state.dashStyle}
            onChange={this.handleDashChange.bind(this)}
          >
            <MenuItem key={1} value="Solid" primaryText="Solid"/>
            <MenuItem key={2} value="ShortDash" primaryText="ShortDash"/>
            <MenuItem key={3} value="ShortDot" primaryText="ShortDot"/>
          </Menu>
        </Popover>
{
这是我的国家({
开放:是的,
主持人:event.currentTarget,
});
}}>短跑风格
使用这两个组件


希望这对您有所帮助。

您所说的是默认行为。你进口了吗?@LeeHanKyeol,没有。它能帮我什么忙?是否需要在标签中添加onClick属性?谢谢。我现在使用了另一种解决方法:绝对定位下拉列表,在标签上加上填充,这样用户就有了单击标签的印象,但实际上是下拉列表本身被单击了。