Prevent Up and Down keys being overriden by MUI listeners when not in use (#698)

This commit is contained in:
saltrafael 2022-01-14 14:55:42 -03:00 committed by GitHub
parent 53155bd7d6
commit 83378174b7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -323,6 +323,27 @@ export default function TextareaWithSuggestions(props: Props) {
return () => window.removeEventListener('keydown', handleKeyDown);
}, [handleSelect, highlightedSuggestion, suggestionTerm]);
// Prevent keyboard keys like Up and Down being overriden by MUI listeners when not in use
React.useEffect(() => {
const inputElement = inputRef && inputRef.current;
function overrideKeyHandling(event) {
if (!suggestionTerm) {
event.stopPropagation();
}
}
if (inputElement) {
inputElement.addEventListener('keydown', overrideKeyHandling);
}
return () => {
if (inputElement) {
inputElement.removeEventListener('keydown', overrideKeyHandling);
}
};
}, [inputRef, suggestionTerm]);
/** ------ **/
/** Render **/
/** ------ **/