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

Focus emoji picker search input #2429

Merged
merged 5 commits into from
Apr 21, 2021
Merged

Focus emoji picker search input #2429

merged 5 commits into from
Apr 21, 2021

Conversation

roryabraham
Copy link
Contributor

@roryabraham roryabraham commented Apr 15, 2021

Details

Following-up on #1991 (comment). During testing, we found a minor issue that when the EmojiPickerMenu is first opened, neither the ReportActionCompose nor the emoji search input are focused. We decided that because that was already a big PR it would be easier to handle the focus issue in a follow-up PR.

Note: I also found an issue with the existing implementation where the search input was displayed on mobile web, which we don't want for the same reasons we don't want it to display on mobile (i.e: the native keyboard competes with the emoji picker.

Fixed Issues

n/a.

Tests / QA Steps (Web/Desktop)

  1. Click on the emoji icon in the ReportActionCompose to open the emoji picker.
  2. Verify that the emoji picker search input is focused, and that you can immediately type to search emojis.
  3. Click an emoji and verify that it populates the ReportActionCompose (make sure it doesn't take two clicks)
  4. Close the emoji picker.
  5. Verify that the ReportActionCompose has focus again.

Tests / QA Steps (iOS/Android/mWeb)

Just make sure that the emoji picker still works like normal. This PR should have no other effect.

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

image

Mobile Web

image

Desktop

image

iOS

image

Android

image

@roryabraham roryabraham requested a review from a team as a code owner April 15, 2021 23:50
@roryabraham roryabraham self-assigned this Apr 15, 2021
@MelvinBot MelvinBot requested review from Luke9389 and removed request for a team April 15, 2021 23:50
@roryabraham roryabraham changed the title Focus emoji picker search input [HOLD] Focus emoji picker search input Apr 16, 2021
@roryabraham roryabraham changed the title [HOLD] Focus emoji picker search input Focus emoji picker search input Apr 16, 2021
Copy link
Contributor

@Luke9389 Luke9389 left a comment

Choose a reason for hiding this comment

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

Nice job. Just tiny comment

forwardedRef: () => {},
};

class WithWindowDimensions extends Component {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be camelCase I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually had to change this to PascalCase so that it can be rendered like <WithWindowDimensions />. I guess if you try and do <withWindowDimensions />, react will think you're trying to render regular html like <input> or <table> or whatever and complain that it doesn't support the <withWindowDimensions /> tag. Maybe I was just holding something wrong, but changing it to PascalCase fixed the error.

Anyways, the good news is that it uses a default export so it can still be imported and used in camelCase.

Copy link
Contributor

Choose a reason for hiding this comment

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

Huh, how strange.

Maybe we should change our code style to capitalize components. All of the ones in the react native docs are PascalCase...

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why it was working before but not now. Can you account for why that discrepancy is occurring?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Short answer:

Before, we weren't ever explicitly rendering it like <withWindowDimensions />, but now we are explicitly rendering it on line 86.


Long Answer:

withWindowDimensions as you know is a HOC, which means that it is a function that takes a component as input and returns a component. You'll notice that the WrappedComponent is using PascalCase, and is rendered starting on line 69.

Before, we weren't doing any explicit rendering of the withWindowDimensions component itself, but rather calling it as a function, getting a component back, and rendering that.

We are able to pass props through withWindowDimensions to the WrappedComponent by simply drilling them down (as done on line 62 before or line 71 now). But refs work differently. In order to pass a ref through to a wrapped component, we need to use React.forwardRef, so what we're doing now is something like this:

React.forwardRef(withWindowDimesions(WrappedComponent))

But in order to forward the ref through withWindowDimensions, withWindowDimensions needs to accept the ref as a prop and then pass it as a ref to the WrappedComponent. So that's why we're explicitly rendering <WithWindowDimensions /> on line 86 - so that we can pass the forwarded ref as a prop.


Caveat: I admit this feels a bit weird but I can't think of any other way to pass a ref through a HOC to a wrapped component. Open to any ideas if there's an easier way to do this.

Reference for where I found this solution: https://dev.to/justincy/using-react-forwardref-and-an-hoc-on-the-same-component-455m

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should change our code style to capitalize components

Well, that is normally how we do this, except all our HOCs use camelCase by convention. This still uses camelCase everywhere else in the code and works just the same, except it can now accept a ref and pass it through.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah ok, thanks for this explanation! Very nice ❤️

Copy link
Contributor

Choose a reason for hiding this comment

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

Just passing through, but I agree with Luke that this should follow the camel case convention like other HOC.

My 2 cents, it would have been simpler to just drill the withWindowDimensions props down through EmojiPickerMenu. Instead we increased the complexity of a very general thing to cover a use case that we will very rarely run into.

Comment on lines +81 to +83
WithWindowDimensions.propTypes = propTypes;
WithWindowDimensions.defaultProps = defaultProps;
WithWindowDimensions.displayName = `withWindowDimensions(${getComponentDisplayName(WrappedComponent)})`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here on the camelCase comment

Copy link
Contributor

@Luke9389 Luke9389 left a comment

Choose a reason for hiding this comment

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

LGTM

@stitesExpensify stitesExpensify merged commit d779199 into main Apr 21, 2021
@stitesExpensify stitesExpensify deleted the Rory-FocusEmojiPicker branch April 21, 2021 22:00
@OSBotify
Copy link
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@OSBotify
Copy link
Contributor

OSBotify commented May 8, 2021

🚀 Deployed to production in version: 1.0.39-5🚀

platform result
🤖 android 🤖 failure ❌
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants