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

Losing text selection / focus in mobile browsers #1806

Closed
cadars opened this issue Aug 26, 2021 · 9 comments
Closed

Losing text selection / focus in mobile browsers #1806

cadars opened this issue Aug 26, 2021 · 9 comments
Labels
sponsor 💖 This issue or pull request was created by a Tiptap sponsor Type: Bug The issue or pullrequest is related to a bug

Comments

@cadars
Copy link
Contributor

cadars commented Aug 26, 2021

Description
When toggling marks or nodes with buttons, the virtual keyboard slides up and down, and in some cases (iOS Safari) loses the text selection entirely and doesn't slide back.

I believe this is a newly introduced bug, I have a build from 2021-08-09 behaving normally.

Steps to reproduce the bug
Steps to reproduce the behavior:

  1. Use a mobile browser (tested with Android Chrome and latest iOS Safari)
  2. Open the default example or any other with a menu.
  3. Select some text and apply formatting with the menu buttons.
  4. Virtual keyboard slides up and down, sometimes losing the text selection.

Expected behavior
Text selection should stay focused.

@cadars cadars added Type: Bug The issue or pullrequest is related to a bug v2 labels Aug 26, 2021
@github-actions github-actions bot added the sponsor 💖 This issue or pull request was created by a Tiptap sponsor label Aug 26, 2021
@hanspagel
Copy link
Contributor

What if you add event.preventDefault to the buttons?

@hanspagel
Copy link
Contributor

Ah, okay. 😛

@cadars
Copy link
Contributor Author

cadars commented Aug 27, 2021

Thanks for the quick fix on iOS! 🙌

But I think the issue is still happening with Chrome Android, for both Vue and React in the default example.

@philippkuehn
Copy link
Contributor

it’s fixed in the packages but we have to update the demos 😅

@cadars
Copy link
Contributor Author

cadars commented Sep 21, 2021

@philippkuehn Can you check on an Android phone if this is really fixed? I tried on two different devices, latest Chrome, and the virtual keyboard still slides up and down… (this doesn’t happen on the main demo of the ProseMirror website, for comparison)

@philippkuehn philippkuehn reopened this Sep 21, 2021
@hanspagel hanspagel removed the v2 label Sep 28, 2021
@denweng
Copy link

denweng commented Mar 7, 2022

This approach soves the Problem on most* Devices. Used in am button with react:

 onMouseDown={(e) => {
          e.preventDefault()
          e.stopPropagation()
          editor.chain().focus().setColor('#F98181').run()
        }}
  • very strange behaviour on some devices, e.g. Galaxy Tab A with Android 10
    Only when the curor is at the end of the text there is a problem:
  • click the button
  • the mark gets active (tested with color and bold)
  • typing a key causes to activate the styles/marks of the last char
  • text gets inserted with the unchanged style

... if someona has any idea, I'm happy about every hint

@denweng
Copy link

denweng commented Mar 7, 2022

Ha! This seems to work.
Just add an additional input (move out of sight by css) and switch focus to this and back:

onMouseDown={(e) => {
          e.preventDefault()
          document.getElementById('focusdummy').focus()
          editor.chain().focus().setColor('#70CFF8').run()
        }}

@jyee27
Copy link

jyee27 commented Apr 22, 2022

You can also use ProseMirror's EditorView.focus() to work around this without needing a dummy input:

onClick={e => {
   e.preventDefault();
   editor.view.focus();
   // button logic here
}}

@stale
Copy link

stale bot commented Jul 6, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 6, 2022
@stale stale bot closed this as completed Jul 14, 2022
nk11dev added a commit to nk11dev/notty that referenced this issue Jan 27, 2024
…ed preventing of default event and calling of ProseMirror's "EditorView.focus()" (to fix the virtual keyboard slides up and down behavior, when clicking editor menu buttons).

Details (related GitHub issue):
- "Losing text selection / focus in mobile browsers" ueberdosis/tiptap#1806
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sponsor 💖 This issue or pull request was created by a Tiptap sponsor Type: Bug The issue or pullrequest is related to a bug
Projects
None yet
Development

No branches or pull requests

5 participants