fix(core): resolve focus regression (#6043)

This commit is contained in:
Chase Gruber 2025-01-22 11:15:39 -05:00 committed by GitHub
parent a44a7c38b5
commit fa63c47919
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"@tiptap/core": patch
---
Focus synchronously only if on iOS or Android #4448

View File

@ -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> {
@ -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