我使用了来自 react material-ui 的 TextField
。我想知道用户是否按下了 Ctrl+Enter。我尝试使用 onKeyPress
事件但没有结果。我怎样才能做到这一点?
<TextField
value={this.state.message}
autoFocus={true}
hintText='Type your message here'
onChange={this.onChangeMessage}
onKeyPress={(event) => {
if (event.ctrlKey && event.keyCode == '13')
this.sendMessage();
}}
multiLine={true}
/>
原文由 Akhil Kumar Pilli 发布,翻译遵循 CC BY-SA 4.0 许可协议
onKeyPress
是 此处 提到的 React 支持的合成键事件。试试这个代码: