From 9d0416ee979c147ae7bbd7fe4c900f682fec358b Mon Sep 17 00:00:00 2001 From: s-alves10 Date: Wed, 13 Sep 2023 07:42:14 -0500 Subject: [PATCH] fix: focus on EmojiPicker search input --- src/components/EmojiPicker/EmojiPickerMenu/index.js | 8 +------- .../EmojiPicker/EmojiPickerMenu/index.native.js | 7 ++++++- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/components/EmojiPicker/EmojiPickerMenu/index.js b/src/components/EmojiPicker/EmojiPickerMenu/index.js index 61f6981edbbe..d3268ebc54b0 100755 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.js +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.js @@ -21,7 +21,6 @@ import * as EmojiUtils from '../../../libs/EmojiUtils'; import CategoryShortcutBar from '../CategoryShortcutBar'; import TextInput from '../../TextInput'; import isEnterWhileComposition from '../../../libs/KeyboardShortcut/isEnterWhileComposition'; -import canFocusInputOnScreenFocus from '../../../libs/canFocusInputOnScreenFocus'; const propTypes = { /** Function to add the selected emoji to the main compose text input */ @@ -59,10 +58,6 @@ class EmojiPickerMenu extends Component { // Ref for emoji FlatList this.emojiList = undefined; - // We want consistent auto focus behavior on input between native and mWeb so we have some auto focus management code that will - // prevent auto focus when open picker for mobile device - this.shouldFocusInputOnScreenFocus = canFocusInputOnScreenFocus(); - this.filterEmojis = _.debounce(this.filterEmojis.bind(this), 300); this.highlightAdjacentEmoji = this.highlightAdjacentEmoji.bind(this); this.setupEventHandlers = this.setupEventHandlers.bind(this); @@ -101,7 +96,7 @@ class EmojiPickerMenu extends Component { // get a ref to the inner textInput element e.g. if we do // this.textInput = el} /> this will not // return a ref to the component, but rather the HTML element by default - if (this.shouldFocusInputOnScreenFocus && this.props.forwardedRef && _.isFunction(this.props.forwardedRef)) { + if (this.props.forwardedRef && _.isFunction(this.props.forwardedRef)) { this.props.forwardedRef(this.searchInput); } this.setupEventHandlers(); @@ -507,7 +502,6 @@ class EmojiPickerMenu extends Component { onChangeText={this.filterEmojis} defaultValue="" ref={(el) => (this.searchInput = el)} - autoFocus={this.shouldFocusInputOnScreenFocus} selectTextOnFocus={this.state.selectTextOnFocus} onSelectionChange={this.onSelectionChange} onFocus={() => this.setState({isFocused: true, highlightedIndex: -1, isUsingKeyboardMovement: false})} diff --git a/src/components/EmojiPicker/EmojiPickerMenu/index.native.js b/src/components/EmojiPicker/EmojiPickerMenu/index.native.js index bfdaf1c13d1b..5cd956dae56b 100644 --- a/src/components/EmojiPicker/EmojiPickerMenu/index.native.js +++ b/src/components/EmojiPicker/EmojiPickerMenu/index.native.js @@ -25,6 +25,9 @@ const propTypes = { /** Function to add the selected emoji to the main compose text input */ onEmojiSelected: PropTypes.func.isRequired, + /** The ref to the search input (may be null on small screen widths) */ + forwardedRef: PropTypes.func, + /** Stores user's preferred skin tone */ preferredSkinTone: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), @@ -37,11 +40,12 @@ const propTypes = { }; const defaultProps = { + forwardedRef: () => {}, preferredSkinTone: CONST.EMOJI_DEFAULT_SKIN_TONE, frequentlyUsedEmojis: [], }; -function EmojiPickerMenu({preferredLocale, onEmojiSelected, preferredSkinTone, translate, frequentlyUsedEmojis}) { +function EmojiPickerMenu({preferredLocale, onEmojiSelected, preferredSkinTone, translate, frequentlyUsedEmojis, forwardedRef}) { const emojiList = useAnimatedRef(); // eslint-disable-next-line react-hooks/exhaustive-deps const allEmojis = useMemo(() => EmojiUtils.mergeEmojisWithFrequentlyUsedEmojis(emojis), [frequentlyUsedEmojis]); @@ -168,6 +172,7 @@ function EmojiPickerMenu({preferredLocale, onEmojiSelected, preferredSkinTone, t accessibilityLabel={translate('common.search')} accessibilityRole={CONST.ACCESSIBILITY_ROLE.TEXT} onChangeText={filterEmojis} + ref={forwardedRef} /> {!isFiltered && (