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

fix(drawing): Fix Safari doesn't focus and blur color picker button #1321

Merged
merged 2 commits into from
Jan 21, 2021

Conversation

mxiao6
Copy link
Contributor

@mxiao6 mxiao6 commented Jan 20, 2021

  • Unit test
  • Cross-browser testing

@mxiao6 mxiao6 requested a review from a team as a code owner January 20, 2021 22:04
@mxiao6 mxiao6 force-pushed the fix-safari-picker branch from b1b796b to 60fd033 Compare January 20, 2021 23:23
jstoffan
jstoffan previously approved these changes Jan 20, 2021
if (event.currentTarget.focus) {
// Buttons do not receive focus in Firefox and Safari on MacOS
event.currentTarget.focus();
// When focus() is called, preventDefault must be called to keep the focus from leaving the target
Copy link
Collaborator

Choose a reason for hiding this comment

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

When focus is called within a mousedown handler, just for clarity?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be done in handleClick as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't affect the current flow, but affects the second click of the button. When you click the button the second time, handle blur happens before handle click, which sets the state to false and back to true again. so you cannot close the palette anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The interesting thing here is that even if you click the same button which has the focus, it will still blur and re-focus again, except you handle the logic before everything in handleMouseDown

},
preventDefault: jest.fn(),
};
(getToggleButton(getWrapper()).prop('onMouseDown') as Function)(mockEvent);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I've been favoring simulate because it avoids the need to cast. I've seen the Jest folks say not to use it, but it's there and it works well. Up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I prefer using simulate too, and I tried it first but it doesn't work (I googled it why but it seems sometimes it happens and everyone just use props.onClick() etc. ). Then I have to use this fallback plan.

@mergify mergify bot merged commit bd66999 into box:master Jan 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants