From 3552fb4cf70cf25ee943b94cb6cda90da3aab22d Mon Sep 17 00:00:00 2001 From: Steve Rubin Date: Wed, 30 Oct 2024 13:41:56 -0500 Subject: [PATCH] Prevent default for input events that don't have any characters Seeing cases where some input events with `inputType=deleteContentBackward` are slipping through. These are probably being created via some mechanism other than a keydown directly on the script (e.g., through some accessibility API, or touch control, or some event that's being targeted elsewhere but propagating to the script accidentally). We _never_ want draft.js to do anything in response to an `onInput` in our user case. We were relying on our passed-in `handleBeforeInput` to always return `handled`; but we're only hitting that logic when the input event contains characters. This will hopefully fix that. --- src/component/handlers/edit/editOnBeforeInput.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/component/handlers/edit/editOnBeforeInput.ts b/src/component/handlers/edit/editOnBeforeInput.ts index 70fd82f7e7..929ba54bd2 100644 --- a/src/component/handlers/edit/editOnBeforeInput.ts +++ b/src/component/handlers/edit/editOnBeforeInput.ts @@ -116,6 +116,7 @@ export default function editOnBeforeInput( // In some cases (ex: IE ideographic space insertion) no character data // is provided. There's nothing to do when this happens. if (!chars) { + e.preventDefault(); return; }