Skip to content

Commit

Permalink
fix: fix focus on iOS, fix #1806
Browse files Browse the repository at this point in the history
  • Loading branch information
philippkuehn committed Aug 26, 2021
1 parent 83e2d4d commit 3a06938
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/core/src/commands/focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { EditorState, Selection, TextSelection } from 'prosemirror-state'
import { RawCommands, FocusPosition } from '../types'
import minMax from '../utilities/minMax'
import isTextSelection from '../helpers/isTextSelection'
import isiOS from '../utilities/isiOS'

function resolveSelection(state: EditorState, position: FocusPosition = null) {
if (!position) {
Expand Down Expand Up @@ -48,11 +49,18 @@ export const focus: RawCommands['focus'] = (position = null) => ({
dispatch,
}) => {
const delayedFocus = () => {
// focus within `requestAnimationFrame` breaks focus on iOS
// so we have to call this
if (isiOS()) {
(view.dom as HTMLElement).focus()
}

// For React we have to focus asynchronously. Otherwise wild things happen.
// see: https://github.com/ueberdosis/tiptap/issues/1520
requestAnimationFrame(() => {
if (!editor.isDestroyed) {
view.focus()
editor.commands.scrollIntoView()
}
})
}
Expand Down

0 comments on commit 3a06938

Please sign in to comment.