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

Ignore selectionchange events originating from <input> and <textarea> elements #5795

Merged
merged 2 commits into from
Jan 20, 2025

Conversation

12joan
Copy link
Contributor

@12joan 12joan commented Jan 16, 2025

Description
In Chrome, selectionchange events can fire when <input> and <textarea> elements are appended to the DOM, causing editor.selection to be overwritten in some circumstances. This PR addresses this issue by ignoring selectionchange events originating from these elements.

Issue
Fixes: #5791

Example
Before:

before.mp4

After:

after.mp4

Context
Although Chrome's behaviour is apparently compliant with the spec, other browsers do not behave this way, and the spec may at some point be changed to match other browsers' behaviour. See the Chromium issue for more information.

I'm fairly sure that ignoring selectionchange events from <input> and <textarea> elements will not cause other issues, since actual text selections in these elements do not affect editor.selection. However, if this PR causes a regression, feel free to revert it, since any bug it causes is likely to be more common than the one it fixes.

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.)

Copy link

changeset-bot bot commented Jan 16, 2025

🦋 Changeset detected

Latest commit: 7b99695

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

Copy link
Collaborator

@dylans dylans left a comment

Choose a reason for hiding this comment

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

@12joan could you please verify the one failing integration test (see the changes under file changed) isn't caused by this change? thanks!

@12joan
Copy link
Contributor Author

12joan commented Jan 20, 2025

@dylans It looks like that test is just flaky, unrelated to this change. I ran it a few times locally on both this branch and main, and it seems to fail just as frequently on both, on roughly 7% of runs.

@12joan 12joan requested a review from dylans January 20, 2025 09:52
@dylans dylans merged commit f456dfb into ianstormtaylor:main Jan 20, 2025
7 of 11 checks passed
@github-actions github-actions bot mentioned this pull request Jan 20, 2025
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.

Selection reverts when button click in void element causes input to appear
2 participants