Skip to content

Commit 68373fc

Browse files
authored
Prevent RunFrame keydown blur from breaking Circuit JSON search in the editor preview (#3030)
1 parent 4a3d13d commit 68373fc

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/components/package-port/CodeAndPreview.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,22 @@ export function CodeAndPreview({ pkg, projectUrl, isPackageFetched }: Props) {
187187
})
188188

189189
const isMouseOverRunFrame = useRef(false)
190+
const runFrameContainerRef = useRef<HTMLDivElement>(null)
190191

191192
useEffect(() => {
192-
const handleKeyDown = () => {
193-
if (isMouseOverRunFrame.current) {
194-
;(document.activeElement as HTMLElement)?.blur()
193+
const handleKeyDown = (event: KeyboardEvent) => {
194+
if (!isMouseOverRunFrame.current) return
195+
196+
const target = event.target
197+
if (
198+
target instanceof Node &&
199+
runFrameContainerRef.current?.contains(target)
200+
) {
201+
return
195202
}
203+
;(document.activeElement as HTMLElement | null)?.blur()
196204
}
205+
197206
window.addEventListener("keydown", handleKeyDown)
198207
return () => window.removeEventListener("keydown", handleKeyDown)
199208
}, [])
@@ -268,6 +277,7 @@ export function CodeAndPreview({ pkg, projectUrl, isPackageFetched }: Props) {
268277
: "w-full md:w-1/2",
269278
!state.showPreview && "hidden",
270279
)}
280+
ref={runFrameContainerRef}
271281
onMouseEnter={() => (isMouseOverRunFrame.current = true)}
272282
onMouseLeave={() => (isMouseOverRunFrame.current = false)}
273283
>

0 commit comments

Comments
 (0)