我有一个反应内置的聊天系统,我正在使用材料UI文本字段来提交消息。我希望它的功能类似于网页版的whatsapp或电报。按enter键发送消息,但在shift enter键上,创建新行。我有这个
<TextField
autoFocus={true}
color={"primary"}
multiline
rowsMax={4}
value={inputValue}
fullWidth
placeholder={"Please enter a message"}
onChange={e => {
setInputValue(e.target.value);
}}
/>我应该添加什么来获得该功能,它容易吗?
发布于 2021-06-04 04:28:31
在你的TextField中添加onKeyDown属性
onKeyDown={(e) => {
if(e.keyCode === 13 && !e.shiftKey) {
e.preventDefault();
setInputValue("");
}
}}https://stackoverflow.com/questions/67803596
复制相似问题