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 issue when tabbing into editor in Safari #5383

Merged
merged 1 commit into from
Apr 3, 2023

Conversation

12joan
Copy link
Contributor

@12joan 12joan commented Mar 31, 2023

Description
Fixes an issue in Safari making it imposible to focus the editor using the Tab key when the editor is empty and has a placeholder.

Issue
Fixes: udecode/plate#2315

Example
Before:
https://user-images.githubusercontent.com/4272090/229171039-c9b535b2-9100-41c9-8e81-487eafd2be35.mov

After:
https://user-images.githubusercontent.com/4272090/229171068-a57c2064-4ead-469d-9414-80b0cfc228ca.mov

Context
Safari attempts to place the selection inside the placeholder element, which resulted in a null DOM selection prior to this fix, making it impossible to type even though the editor is technically focused. The simplest solution seems to be to allow Safari to place the selection inside the placeholder, which is what this fix does. (Thanks for discovering this workaround, @hb250131!)

Notice that the caret in the second video is grey and appears at the start of the placeholder, rather than in the middle of it. This is a side effect of the selection being inside the placeholder and happens only when focusing the editor using the Tab key in Safari. It seems to be harmless, but a more robust fix would ensure that the resulting selection is consistent across browsers.

Checks

  • The new code matches the existing patterns and styles.
  • The tests pass with yarn test.
  • The linter passes with yarn lint. (Fix errors with yarn fix.)
  • The relevant examples still work. (Run examples with yarn start.)
  • You've added a changeset if changing functionality. (Add one with yarn changeset add.)

@changeset-bot
Copy link

changeset-bot bot commented Mar 31, 2023

🦋 Changeset detected

Latest commit: dd4943a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
slate-react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dylans dylans merged commit 3c3ea29 into ianstormtaylor:main Apr 3, 2023
@github-actions github-actions bot mentioned this pull request Apr 3, 2023
@12joan 12joan deleted the fix/safari-tab-focus branch April 6, 2023 18:46
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.

Safari: Editor component is not getting focus when there is a placeholder text
2 participants