tldraw/hooks/useSafariFocusOutFix.ts
2021-07-13 20:34:43 +01:00

22 lines
522 B
TypeScript

import { isMobile } from 'utils'
import { useEffect } from 'react'
import state from 'state'
// Send event on iOS when a user presses the "Done" key while editing
// a text element.
function handleFocusOut() {
state.send('BLURRED_EDITING_SHAPE')
}
export default function useSafariFocusOutFix(): void {
useEffect(() => {
if (isMobile()) {
document.addEventListener('focusout', handleFocusOut)
return () => {
document.removeEventListener('focusout', handleFocusOut)
}
}
}, [])
}