Skip to content

Commit

Permalink
Merge pull request #34554 from mkhutornyi/fix-33613
Browse files Browse the repository at this point in the history
fix keyboard arrow maxIndex in emoji/mention suggestion
  • Loading branch information
luacmartins authored Jan 22, 2024
2 parents 062f213 + 614b875 commit 7c93bf8
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,6 @@ const CONST = {
SUGGESTER_INNER_PADDING: 8,
SUGGESTION_ROW_HEIGHT: 40,
SMALL_CONTAINER_HEIGHT_FACTOR: 2.5,
MIN_AMOUNT_OF_SUGGESTIONS: 3,
MAX_AMOUNT_OF_SUGGESTIONS: 20,
MAX_AMOUNT_OF_VISIBLE_SUGGESTIONS_IN_CONTAINER: 5,
HERE_TEXT: '@here',
Expand Down
19 changes: 1 addition & 18 deletions src/libs/SuggestionUtils.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
import CONST from '@src/CONST';

/**
* Return the max available index for arrow manager.
* @param {Number} numRows
* @param {Boolean} isAutoSuggestionPickerLarge
* @returns {Number}
*/
function getMaxArrowIndex(numRows, isAutoSuggestionPickerLarge) {
// rowCount is number of emoji/mention suggestions. For small screen we can fit 3 items
// and for large we show up to 20 items for mentions/emojis
const rowCount = isAutoSuggestionPickerLarge
? Math.min(numRows, CONST.AUTO_COMPLETE_SUGGESTER.MAX_AMOUNT_OF_SUGGESTIONS)
: Math.min(numRows, CONST.AUTO_COMPLETE_SUGGESTER.MIN_AMOUNT_OF_SUGGESTIONS);

// -1 because we start at 0
return rowCount - 1;
}

/**
* Trims first character of the string if it is a space
* @param {String} str
Expand Down Expand Up @@ -44,4 +27,4 @@ function hasEnoughSpaceForLargeSuggestionMenu(listHeight, composerHeight, totalS
return availableHeight > menuHeight;
}

export {getMaxArrowIndex, trimLeadingSpace, hasEnoughSpaceForLargeSuggestionMenu};
export {trimLeadingSpace, hasEnoughSpaceForLargeSuggestionMenu};
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function SuggestionEmoji({

const [highlightedEmojiIndex, setHighlightedEmojiIndex] = useArrowKeyFocusManager({
isActive: isEmojiSuggestionsMenuVisible,
maxIndex: SuggestionsUtils.getMaxArrowIndex(suggestionValues.suggestedEmojis.length, isAutoSuggestionPickerLarge),
maxIndex: suggestionValues.suggestedEmojis.length - 1,
shouldExcludeTextAreaNodes: false,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function SuggestionMention({

const [highlightedMentionIndex, setHighlightedMentionIndex] = useArrowKeyFocusManager({
isActive: isMentionSuggestionsMenuVisible,
maxIndex: SuggestionsUtils.getMaxArrowIndex(suggestionValues.suggestedMentions.length, isAutoSuggestionPickerLarge),
maxIndex: suggestionValues.suggestedMentions.length - 1,
shouldExcludeTextAreaNodes: false,
});

Expand Down

0 comments on commit 7c93bf8

Please sign in to comment.