当我单击 div 中除提交按钮和输入字段之外的任何内容时,输入字段正在清除输入的输入。我该如何解决?输入的输入应该存在,直到提交发生。我有一个带有如下所示输入字段的 div 以及复选框和提交按钮。复选框和提交按钮没有任何问题。
return(
<Downshift
onChange={selection => this.setState({input: selection})}
itemToString={item => (item ? item.first_name : '')}
>
{({
getInputProps,
getItemProps,
getMenuProps,
isOpen,
inputValue,
highlightedIndex,
selectedItem,
}) => (
<div className={classes.container}>
{this.props.disabled ?
<TextField
disabled
label="Name"
fullWidth
inputProps={{
...getInputProps(),
ref: node => {
popperNode = node;
}
}}
// InputProps={{ ...getInputProps() }}
/>
:
<TextField
label="Name"
fullWidth
inputProps={{
...getInputProps(),
ref: node => {
popperNode = node;
}
}}
/>
}
<Popper open={isOpen} anchorEl={popperNode} style={{zIndex:2000}}>
<div {...(isOpen ? getMenuProps({}, { suppressRefError: true }) : {})}>
{inputValue ? this.props.setInputValue(inputValue): null}
<Paper
style={{ marginTop: 8, width: popperNode ? popperNode.clientWidth : null }}
// className={classes.paper}
square>
{ this.state.suggestions
.filter(item => !inputValue || item.first_name.includes(inputValue))
.map((item, index) => (
<MenuItem
component="div"
{...getItemProps({
key: item.person_id,
index,
item,
})}
>
<Typography color="primary">{item.first_name + ' ('+item.person_id +')'} </Typography>
</MenuItem>
))}
</Paper>
</div>
</Popper>
</div>
)}
</Downshift>
);