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(rich-text-input): dropdown focus bug #1145

Merged
merged 3 commits into from
Oct 29, 2019
Merged

Conversation

montezume
Copy link
Contributor

Summary

The bug has to do with calling editor.focus() on any event propagated up to the Toolbar. The inline comment should explain the bug and the fix.

Before

before

After

after

@montezume montezume self-assigned this Oct 29, 2019
@montezume montezume added the 🐛 Type: Bug Something isn't working label Oct 29, 2019
// the reason we keep this here, is because any onClick from our dropdown or our mark buttons
// will propogate to here.
if (!props.editor.value.selection.isFocused) {
setTimeout(focus, 0);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

setTimeout allows our dropdown button onClick to "win" the race condition

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, would this also work with setImmediate(focus) instead of setTimeout(focus, 0)? If so, it should be slightly more performant.

Copy link
Contributor

Choose a reason for hiding this comment

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

CleanShot 2019-10-29 at 14 03 11@2x

Copy link
Contributor

Choose a reason for hiding this comment

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

So we want the focus to happen on the next tick essentially?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tdeekens yeah. There are lots of questions like this in the Slate slack channel. Usually people recommend to use setTimeout.

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 also wouldn't worry about performance. This only happens when

A) The editor is out of focus
B) The user clicks on a mark button or a dropdown button.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for the obvious note: can you add comment please :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also like const = scheduleFocusAfter... would also be cool.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Err, I added like 5 lines of comments? I can add more...

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh wow, I had a completely wrong idea about setImmediate on the browser 🤦‍♂ This ain't node 😅

@montezume
Copy link
Contributor Author

Percy passing 😌

Copy link
Contributor

@tdeekens tdeekens left a comment

Choose a reason for hiding this comment

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

All good. Thanks.

@kodiakhq kodiakhq bot merged commit 0496f29 into master Oct 29, 2019
@kodiakhq kodiakhq bot deleted the ml-fix-dropdown-bug-1 branch October 29, 2019 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants