From 1f21f1188664ebd8f4e96f078ad98f4f6a812293 Mon Sep 17 00:00:00 2001 From: Steve Ruiz Date: Tue, 3 Oct 2023 18:55:51 +0100 Subject: [PATCH] [fix] focus events (#2013) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Somehow the previous focus PR snuck through with broken tests. ### Change Type - [x] `patch` — Bug fix --- packages/editor/src/lib/hooks/useFocusEvents.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/editor/src/lib/hooks/useFocusEvents.ts b/packages/editor/src/lib/hooks/useFocusEvents.ts index 3fad1d755..031fcdafc 100644 --- a/packages/editor/src/lib/hooks/useFocusEvents.ts +++ b/packages/editor/src/lib/hooks/useFocusEvents.ts @@ -1,12 +1,12 @@ import { useLayoutEffect } from 'react' +import { useContainer } from './useContainer' import { useEditor } from './useEditor' /** @internal */ export function useFocusEvents(autoFocus: boolean) { const editor = useEditor() + const container = useContainer() useLayoutEffect(() => { - const container = editor.getContainer() - function handleFocus() { if (!editor.instanceState.isFocused) { editor.updateInstanceState({ isFocused: true }) @@ -14,16 +14,18 @@ export function useFocusEvents(autoFocus: boolean) { } container.addEventListener('focus', handleFocus) + container.addEventListener('pointerdown', handleFocus) if (autoFocus && !editor.instanceState.isFocused) { editor.updateInstanceState({ isFocused: true }) - editor.getContainer().focus() + container.focus() } else if (editor.instanceState.isFocused) { editor.updateInstanceState({ isFocused: false }) } return () => { container.removeEventListener('focus', handleFocus) + container.removeEventListener('pointerdown', handleFocus) } - }, [editor, autoFocus]) + }, [editor, container, autoFocus]) }