diff --git a/src/components/EmojiPicker/EmojiPicker.tsx b/src/components/EmojiPicker/EmojiPicker.tsx index b588d1af72769..d3a9d1d1327dd 100644 --- a/src/components/EmojiPicker/EmojiPicker.tsx +++ b/src/components/EmojiPicker/EmojiPicker.tsx @@ -11,9 +11,11 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useStyleUtils from '@hooks/useStyleUtils'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; +import blurActiveElement from '@libs/Accessibility/blurActiveElement'; import type {AnchorOrigin, EmojiPickerRef, EmojiPopoverAnchor, OnEmojiSelected, OnModalHideValue, OnWillShowPicker} from '@libs/actions/EmojiPickerAction'; import {isMobileChrome} from '@libs/Browser'; import calculateAnchorPosition from '@libs/calculateAnchorPosition'; +import DomUtils from '@libs/DomUtils'; import {close} from '@userActions/Modal'; import CONST from '@src/CONST'; import EmojiPickerMenu from './EmojiPickerMenu'; @@ -116,6 +118,10 @@ function EmojiPicker({viewportOffsetTop}: EmojiPickerProps, ref: ForwardedRef { + const activeElementId = DomUtils.getActiveElement()?.id; + if (activeElementId !== CONST.COMPOSER.NATIVE_ID) { + blurActiveElement(); + } const currOnModalHide = onModalHide.current; onModalHide.current = () => { if (currOnModalHide) { diff --git a/src/libs/focusComposerWithDelay/setTextInputSelection.ts b/src/libs/focusComposerWithDelay/setTextInputSelection.ts index fbbc4738702fc..81757f691dec3 100644 --- a/src/libs/focusComposerWithDelay/setTextInputSelection.ts +++ b/src/libs/focusComposerWithDelay/setTextInputSelection.ts @@ -6,9 +6,9 @@ const setSelectionRange = shouldSetSelectionRange(); const setTextInputSelection = (textInput: InputType, forcedSelectionRange: Selection) => { if (setSelectionRange) { - (textInput as HTMLTextAreaElement).setSelectionRange(forcedSelectionRange.start, forcedSelectionRange.end); + (textInput as HTMLTextAreaElement).setSelectionRange?.(forcedSelectionRange.start, forcedSelectionRange.end); } else { - (textInput as TextInput).setSelection(forcedSelectionRange.start, forcedSelectionRange.end); + (textInput as TextInput).setSelection?.(forcedSelectionRange.start, forcedSelectionRange.end); } };