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

Bullet/Editable: Use fastClick for clickHandler #2752

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

ethan-james
Copy link
Collaborator

@ethan-james ethan-james commented Jan 2, 2025

Fix #1691

The Bullet component was using onClick to dispatch its setCursor action, which has a noticeable delay on iOS. Wrapping the click handler in fastClick solves the issue.

In Editable, the onTap handler was ignoring taps that would cause the keyboard to open, and falling back to the onFocus handler after a 300ms delay. It was necessary to intercept those taps and set the cursor with a manual offset to put the caret back at the end of the thought on iOS Safari. There was also some flakiness where selection.set wasn't always opening the keyboard, so now it calls contentRef.current.focus() explicitly.

@ethan-james ethan-james marked this pull request as draft January 2, 2025 22:19
@ethan-james ethan-james marked this pull request as ready for review January 4, 2025 00:11
@@ -203,6 +203,8 @@ const Editable = ({
// set offset to null to allow the browser to set the position of the selection
let offset = null

if (isTouch && isSafari() && contentRef.current?.innerHTML.length) offset = contentRef.current.innerHTML.length
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The caret was getting positioned at the end of the thought somehow onFocus, so I wanted to preserve that behavior onTap.

@@ -51,6 +51,7 @@ const useEditMode = ({
selection.clear()
} else {
selection.set(contentRef.current, { offset: editingCursorOffset || 0 })
if (isTouch && isSafari()) contentRef.current?.focus()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not quite sure why this is necessary, but it was having the following problem on iOS Safari:

  1. Tap a thought - cursor moves, keyboard stays closed
  2. Tap it again - keyboard opens
  3. Close keyboard
  4. Tap it again - keyboard does not open

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, good catch.

I'll create a separate issue to get to the bottom of this.

@ethan-james ethan-james changed the title Bullet: Use fastClick for clickHandler Bullet/Editable: Use fastClick for clickHandler Jan 5, 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.

[iOS] setCursor is delayed when keyboard is up
2 participants