diff --git a/src/libs/KeyboardShortcut/isEnterWhileComposition.ts b/src/libs/KeyboardShortcut/isEnterWhileComposition.ts index 71ec27f21c13..6e65ee96aff1 100644 --- a/src/libs/KeyboardShortcut/isEnterWhileComposition.ts +++ b/src/libs/KeyboardShortcut/isEnterWhileComposition.ts @@ -16,10 +16,23 @@ const isEnterWhileComposition = (event: KeyboardEvent | React.KeyboardEvent): bo // On Safari, isComposing returns false on Enter keypress event even for IME confirmation. Although keyCode is deprecated, // reading keyCode is the only way available to distinguish Enter keypress event for IME confirmation. if (CONST.BROWSER.SAFARI === Browser.getBrowser()) { + // eslint-disable-next-line @typescript-eslint/no-deprecated return event.keyCode === 229; } - return event.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey && (event as unknown as NativeSyntheticEvent)?.nativeEvent?.isComposing; + // Check if this is a native KeyboardEvent (has isComposing directly) or a React synthetic event (has nativeEvent.isComposing) + // For native KeyboardEvent, isComposing is directly on the event + // For React synthetic events, it's on event.nativeEvent.isComposing + let isComposing: boolean | undefined; + + if (event instanceof KeyboardEvent) { + isComposing = event.isComposing; + } else { + const nativeEvent = (event as unknown as NativeSyntheticEvent)?.nativeEvent; + isComposing = nativeEvent?.isComposing; + } + + return event.key === CONST.KEYBOARD_SHORTCUTS.ENTER.shortcutKey && !!isComposing; }; export default isEnterWhileComposition;