Fix issue when tabbing into editor in Safari #5383
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
yarn test
.yarn lint
. (Fix errors withyarn fix
.)yarn start
.)yarn changeset add
.)