-
Notifications
You must be signed in to change notification settings - Fork 26
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
Conversation
// 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 😅
Percy passing 😌 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All good. Thanks.
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
After