From 85c6cbc8381bdfc0b15bbd0c2d3e8df432f4c5c4 Mon Sep 17 00:00:00 2001 From: HitenChawda Date: Thu, 2 Jan 2025 23:30:53 +0530 Subject: [PATCH] Fixed before input bug (#31957) --- .../src/events/plugins/BeforeInputEventPlugin.js | 4 ++-- .../plugins/__tests__/BeforeInputEventPlugin-test.js | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/react-dom-bindings/src/events/plugins/BeforeInputEventPlugin.js b/packages/react-dom-bindings/src/events/plugins/BeforeInputEventPlugin.js index 96431e9fe1519..334a3a3ce3fcf 100644 --- a/packages/react-dom-bindings/src/events/plugins/BeforeInputEventPlugin.js +++ b/packages/react-dom-bindings/src/events/plugins/BeforeInputEventPlugin.js @@ -59,7 +59,7 @@ function registerEvents() { registerTwoPhaseEvent('onBeforeInput', [ 'compositionend', 'keypress', - 'textInput', + 'beforeinput', 'paste', ]); registerTwoPhaseEvent('onCompositionEnd', [ @@ -281,7 +281,7 @@ function getNativeBeforeInputChars( hasSpaceKeypress = true; return SPACEBAR_CHAR; - + case 'beforeinput': // ensure that before input event is listened to case 'textInput': // Record the characters to be added to the DOM. const chars = nativeEvent.data; diff --git a/packages/react-dom/src/events/plugins/__tests__/BeforeInputEventPlugin-test.js b/packages/react-dom/src/events/plugins/__tests__/BeforeInputEventPlugin-test.js index 353f2de4d8687..5ad038fa485f0 100644 --- a/packages/react-dom/src/events/plugins/__tests__/BeforeInputEventPlugin-test.js +++ b/packages/react-dom/src/events/plugins/__tests__/BeforeInputEventPlugin-test.js @@ -123,7 +123,7 @@ describe('BeforeInputEventPlugin', () => { }, { eventSimulator: simulateEvent, - eventSimulatorArgs: ['textInput', {data: 'abcß'}], + eventSimulatorArgs: ['beforeinput', {data: 'abcß'}], }, { eventSimulator: simulateKeyboardEvent, @@ -161,7 +161,7 @@ describe('BeforeInputEventPlugin', () => { }, { eventSimulator: simulateEvent, - eventSimulatorArgs: ['textInput', {data: '\uD83D\uDE0A'}], + eventSimulatorArgs: ['beforeinput', {data: '\uD83D\uDE0A'}], }, { eventSimulator: simulateKeyboardEvent, @@ -236,7 +236,7 @@ describe('BeforeInputEventPlugin', () => { { run: ({beforeInputEvent, spyOnBeforeInput}) => { expect(spyOnBeforeInput).toHaveBeenCalledTimes(1); - expect(beforeInputEvent.nativeEvent.type).toBe('textInput'); + expect(beforeInputEvent.nativeEvent.type).toBe('beforeinput'); expect(beforeInputEvent.type).toBe('beforeinput'); expect(beforeInputEvent.data).toBe('abcß'); }, @@ -288,7 +288,7 @@ describe('BeforeInputEventPlugin', () => { { run: ({beforeInputEvent, spyOnBeforeInput}) => { expect(spyOnBeforeInput).toHaveBeenCalledTimes(1); - expect(beforeInputEvent.nativeEvent.type).toBe('textInput'); + expect(beforeInputEvent.nativeEvent.type).toBe('beforeinput'); expect(beforeInputEvent.type).toBe('beforeinput'); expect(beforeInputEvent.data).toBe('\uD83D\uDE0A'); },