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

Don't focus when ref composer is unmounted #25981

Merged
merged 10 commits into from
Aug 28, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,19 @@ function ReportActionCompose({
return translate('reportActionCompose.writeSomething');
}, [report, blockedFromConcierge, translate, conciergePlaceholderRandomIndex]);

const focus = () => {
if (composerRef === null || composerRef.current === null) {
return;
}
composerRef.current.focus(true);
};

const isKeyboardVisibleWhenShowingModalRef = useRef(false);
const restoreKeyboardState = useCallback(() => {
if (!isKeyboardVisibleWhenShowingModalRef.current) {
return;
}
composerRef.current.focus(true);
focus();
isKeyboardVisibleWhenShowingModalRef.current = false;
}, []);

Expand Down Expand Up @@ -403,7 +410,7 @@ function ReportActionCompose({
{DeviceCapabilities.canUseTouchScreen() && isMediumScreenWidth ? null : (
<EmojiPickerButton
isDisabled={isBlockedFromConcierge || disabled}
onModalHide={() => composerRef.current.focus(true)}
onModalHide={focus}
Copy link
Member Author

@rushatgabhane rushatgabhane Aug 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mountiny this might be a noob question, but are these both equivalent?

  1. onModalHide={focus}
  2. onModalHide={() => focus()}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe they are equivalent. The first option is passing the function directly as a reference so in theory its slightly more efficient because the second option everytime creates a new inline function that calls the focus function

onEmojiSelected={(...args) => composerRef.current.replaceSelectionWithText(...args)}
emojiPickerID={report.reportID}
/>
Expand Down
Loading