import React, { useEffect } from "react"; import { useFocusable } from '@noriginmedia/norigin-spatial-navigation'; import { Link, navigate } from "gatsby"; const isBrowser = typeof window !== "undefined" function CompatBtn({autoFocus, href, onClick, group, target, children, className, ...props}) { const { ref, focused, focusSelf} = useFocusable(); useEffect(() => { if (!autoFocus) return; focusSelf() }, [focusSelf]) if (onClick) href = "#!" if (focused && ref.current) { ref.current?.focus() } if (isBrowser) { window.addEventListener("keyup", (ev) => { if (!focused) return; if (document.activeElement !== ref.current) return; if (ev.key === "Enter" || ev.key === " ") { ref.current?.click() } }) } if (target !== "_blank" && !group && !onClick) { return {children} } else if (!group && !onClick) { return {children} } else { return } } export default CompatBtn