-
Notifications
You must be signed in to change notification settings - Fork 123
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
base: main
Are you sure you want to change the base?
Bullet/Editable: Use fastClick for clickHandler #2752
Conversation
@@ -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 |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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:
- Tap a thought - cursor moves, keyboard stays closed
- Tap it again - keyboard opens
- Close keyboard
- Tap it again - keyboard does not open
There was a problem hiding this comment.
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.
Fix #1691
The
Bullet
component was usingonClick
to dispatch itssetCursor
action, which has a noticeable delay on iOS. Wrapping the click handler infastClick
solves the issue.In
Editable
, theonTap
handler was ignoring taps that would cause the keyboard to open, and falling back to theonFocus
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 whereselection.set
wasn't always opening the keyboard, so now it callscontentRef.current.focus()
explicitly.