私はmaterial-uiのオートコンプリートを使用しており、ボタンをクリックするたびに選択した値を削除しようとしていますが、それを行う方法が見つかりません。何か案が?
<Autocomplete
className={classes.techListBox}
disableCloseOnSelect={true}
multiple
options={this.props.displayProject.techList}
getOptionLabel={options => options.title}
defaultValue={this.props.displayProject.techName}
onChange={(e, techs) => {
this.formatTechID(techs);
}}
renderInput={params => (
<TextField
{...params}
variant="outlined"
placeholder={t("tech")}
margin="normal"
fullWidth
/>
)}
></Autocomplete>```
オートコンプリートで値(状態)とonChangeイベントを設定する必要があります:)残りのボタンをクリックすると、状態がリセットされます:)
const [value, setValue] = React.useState(null);
<Autocomplete
value={value}
onChange={(event, newValue) => {
setValue(newValue);
}}
>
<button onClick={() => setValue(null)}>Reset autocomplete</button>
私はあなたのために動作するデモを作成しました:https://codesandbox.io/s/material-demo-zqz4v
その他の質問についてはコメントしてください:)
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加