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): fix for safari #1150

Merged
merged 7 commits into from
Nov 1, 2019
Merged

fix(rich-text-input): fix for safari #1150

merged 7 commits into from
Nov 1, 2019

Conversation

montezume
Copy link
Contributor

Summary

Currently the RichTextInput and the LocalizedRichTextInput are completely broken in Safari.

After a lot of debugging, I figured out that combining slate + contenteditable + <output> lead to this problem.

bug

In case anyone has forgotten, the reason why we wanted to use output in the first place, is because it natively supports working with labels and htmlFor.

Instead, I added a hidden input and I manually focus the RichTextInput based on that.

@montezume montezume added the 🐛 Type: Bug Something isn't working label Oct 31, 2019
@montezume montezume self-assigned this Oct 31, 2019
@montezume
Copy link
Contributor Author

I would appreciate a quick review since this is a critical bug. cc @jonnybel

const children = React.cloneElement(next(), {
tagName: 'output',
id: internalId,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we don't want two elements with the same id, so we change the <div contenteditable> id to an internal id

<HiddenInput
isFocused={isFocused}
handleFocus={editor.focus}
id={props.id}
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 hidden input receives the "real" id, so that it can receive label focus

@@ -129,6 +134,11 @@ const renderEditor = (props, editor, next) => {
return (
<Editor editor={editor} {...passedProps}>
{children}
<HiddenInput
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this like a focus trap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you explain what a focus trap is?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a trap for the page's focus or the user's ability to tab around. So only any child within the focus-trap can be focussed. I wasn't sure if this was what we're doing here just couldn't derive fromt the name HiddenInput.

Copy link
Contributor Author

@montezume montezume Nov 1, 2019

Choose a reason for hiding this comment

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

To understand this, we need to step back.

When you write this in HTML, what does it mean?

<label htmlFor="name">Name</label>

It associates this label with the text "Name", with the <input> who's id is "name". Right?

<input>. Not div. Not span. You can't associate a label with a <div> or a <span>.

That's the problem.

Before we were not rendering a <div>, we were rendering an <output>.

You can associate labels with <outputs>

However, contenteditable outputs break in Safari.

The idea of the HiddenInput, is to allow users to specify label's with htmlFor.

Does that clear it up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah got it. Thanks. So it's just the "label-anchor" or something like that.

Copy link
Contributor

@jonnybel jonnybel left a comment

Choose a reason for hiding this comment

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

Sad to see the <output> trick go :(

The new solution looks good 👍

@montezume montezume merged commit 9f99224 into master Nov 1, 2019
@montezume montezume deleted the ml-safari-fix branch November 1, 2019 12:23
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