Skip to content

Commit

Permalink
fix(core): resolve focus regression (#6043)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpgruber authored Jan 22, 2025
1 parent a44a7c3 commit fa63c47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/thirty-deers-attend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@tiptap/core": patch
---

Focus synchronously only if on iOS or Android #4448
8 changes: 7 additions & 1 deletion packages/core/src/commands/focus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { isTextSelection } from '../helpers/isTextSelection.js'
import { resolveFocusPosition } from '../helpers/resolveFocusPosition.js'
import { FocusPosition, RawCommands } from '../types.js'
import { isAndroid } from '../utilities/isAndroid.js'
import { isiOS } from '../utilities/isiOS.js'

declare module '@tiptap/core' {
interface Commands<ReturnType> {
Expand Down Expand Up @@ -42,7 +44,11 @@ export const focus: RawCommands['focus'] = (position = null, options = {}) => ({
}

const delayedFocus = () => {
(view.dom as HTMLElement).focus()
// focus within `requestAnimationFrame` breaks focus on iOS and Android
// so we have to call this
if (isiOS() || isAndroid()) {
(view.dom as HTMLElement).focus()
}

// For React we have to focus asynchronously. Otherwise wild things happen.
// see: https://github.com/ueberdosis/tiptap/issues/1520
Expand Down

0 comments on commit fa63c47

Please sign in to comment.