Sim*_*ong 9 reactjs material-ui
我一直在编写一个自定义的 Material-UISelect
下拉列表,它的顶部有一个可选的文本字段,允许用户在Select
有很多条目的情况下搜索/过滤项目。
我正在努力解决如何Select
在单击文本字段(呈现为 )时保持打开状态并仅具有正常行为(选择常规时InputBase
关闭。Select
MenuItem
CodeSandbox 在这里:https ://codesandbox.io/s/inspiring-newton-9qsyf
const searchField: TextField = props.searchable ? (
<InputBase
className={styles.searchBar}
onClick={(event: Event) => {
event.stopPropagation();
event.preventDefault();
}}
endAdornment={
<InputAdornment position="end">
<Search />
</InputAdornment>
}
/>
) : null;
return (
<FormControl>
<Select
className={styles.root}
input={<InputBase onClick={(): void => setIconOpen(!iconOpen)} />}
onBlur={(): void => setIconOpen(false)}
IconComponent={iconOpen ? ExpandMore : ExpandLess}
{...props}
>
{searchField}
{dropdownElements.map(
(currEntry: string): HTMLOptionElement => (
<MenuItem key={currEntry} value={currEntry}>
{currEntry}
</MenuItem>
)
)}
</Select>
</FormControl>
);
Run Code Online (Sandbox Code Playgroud)
正如你在上面看到的,我尝试使用stopPropagation
andpreventDefault
但没有成功。
归档时间: |
|
查看次数: |
23163 次 |
最近记录: |