[英]Select dropdown trigger on key click
I am working on react and I am using Select component provided by the material.我正在研究反应,我正在使用材料提供的 Select 组件。 ( https://material-ui.com/components/selects/ ).
( https://material-ui.com/components/selects/ )。 Upon opening the dropdown, if I press a key and there is an option that starts with that key, the corresponding option is automatically selected.
打开下拉菜单后,如果我按下一个键并且有一个以该键开头的选项,则会自动选择相应的选项。 This is true for normal HTML select element too.
对于普通的 HTML 选择元素也是如此。 For Example - If available options are Mike, Robert, Julie, Casie and after opening dropdown I press key R on my keyboard, the selection jumps to Robert automatically Is there any way I can prevent this behavior?
例如 - 如果可用选项是 Mike、Robert、Julie、Casie,在打开下拉菜单后,我按键盘上的 R 键,选择会自动跳转到 Robert 有什么办法可以防止这种行为? I tried to add onKeyPress event to Select component but it is not getting fired.
我试图将 onKeyPress 事件添加到 Select 组件,但它没有被触发。
Steps to reproduce:重现步骤:
You can stop the event propagation from the <MenuItem>
as follows您可以按如下方式从
<MenuItem>
停止事件传播
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={age}
onKeyDown={e => e.stopPropagation()}
onChange={handleChange}
>
<MenuItem onKeyDown={e => e.stopPropagation()} value={10}>Ten</MenuItem>
<MenuItem onKeyDown={e => e.stopPropagation()} value={20}>Twenty</MenuItem>
<MenuItem onKeyDown={e => e.stopPropagation()} value={30}>Thirty</MenuItem>
</Select>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.