Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent mentions from popping up unexpectadly #29951

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ function ComposerWithSuggestions({
<Suggestions
ref={suggestionsRef}
isComposerFullSize={isComposerFullSize}
isComposerFocused={textInputRef.current && textInputRef.current.isFocused()}
updateComment={updateComment}
composerHeight={composerHeight}
measureParentContainer={measureParentContainer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function SuggestionMention({
forwardedRef,
isAutoSuggestionPickerLarge,
measureParentContainer,
isComposerFocused,
}) {
const {translate} = useLocalize();
const [suggestionValues, setSuggestionValues] = useState(defaultSuggestionsValues);
Expand Down Expand Up @@ -181,7 +182,7 @@ function SuggestionMention({

const calculateMentionSuggestion = useCallback(
(selectionEnd) => {
if (shouldBlockCalc.current || selectionEnd < 1) {
if (shouldBlockCalc.current || selectionEnd < 1 || !isComposerFocused) {
shouldBlockCalc.current = false;
resetSuggestions();
return;
Expand Down Expand Up @@ -229,7 +230,7 @@ function SuggestionMention({
}));
setHighlightedMentionIndex(0);
},
[getMentionOptions, personalDetails, resetSuggestions, setHighlightedMentionIndex, value],
[getMentionOptions, personalDetails, resetSuggestions, setHighlightedMentionIndex, value, isComposerFocused],
);

useEffect(() => {
Expand Down
2 changes: 2 additions & 0 deletions src/pages/home/report/ReportActionCompose/Suggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ function Suggestions({
resetKeyboardInput,
measureParentContainer,
isAutoSuggestionPickerLarge,
isComposerFocused,
}) {
const suggestionEmojiRef = useRef(null);
const suggestionMentionRef = useRef(null);
Expand Down Expand Up @@ -103,6 +104,7 @@ function Suggestions({
composerHeight,
isAutoSuggestionPickerLarge,
measureParentContainer,
isComposerFocused,
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const baseProps = {

/** Meaures the parent container's position and dimensions. */
measureParentContainer: PropTypes.func.isRequired,

/** Report composer focus state */
isComposerFocused: PropTypes.bool,
};

const implementationBaseProps = {
Expand Down