Change disable attribute in react select with material UI

烈酒焚心 提交于 2021-02-11 14:23:32

问题


I am trying to change disable attribute in select on button click in react application using material ui My button code is:

<AsistButton variant="outlined" color="primary" className={classes.button}>X</AsistButton>

and from select is:

<NativeSelect
    value={person}
    className={classes.margin}
    onChange={handleChangeSelect}
    input={<BootstrapInput name="person" id="person-customized-native-simple"/>}
    disabled
>
    <option value=""/>
    <option value={10}>Peter</option>
    <option value={20}>Alex</option>
    <option value={30}>Jon</option>
</NativeSelect>

what function I need to define to achieve that.


回答1:


you should write a counter in state like:

state={disabled: false}

and the on click should turn this.state.disabled to true.

after that in the NativeSelect component set disabled to

disabled={this.state.disabled}


来源:https://stackoverflow.com/questions/56637567/change-disable-attribute-in-react-select-with-material-ui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!