From d3de9d88bfa5f0e88236560997a170050b43edd4 Mon Sep 17 00:00:00 2001 From: flakeed Date: Fri, 14 Apr 2023 20:07:41 +0000 Subject: [PATCH 1/2] fix the issue of cursor movement using arrow keys in the search bar for links --- imports/cyto-react-links-card.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/imports/cyto-react-links-card.tsx b/imports/cyto-react-links-card.tsx index 31acd8ca..7894e134 100644 --- a/imports/cyto-react-links-card.tsx +++ b/imports/cyto-react-links-card.tsx @@ -224,7 +224,7 @@ export const CytoReactLinksCard = React.memo(({ setSelectedLink((prevLinkId) => prevLinkId == linkId ? 0 : linkId); }, []); - useHotkeys('up,right,down,left', e => { + useHotkeys('up,down', e => { e.preventDefault(); e.stopPropagation(); let index = elements.findIndex(e => e.id == selectedLink); @@ -234,10 +234,10 @@ export const CytoReactLinksCard = React.memo(({ let next = elements[index]; if (!selectedLink) { setSelectedLink(next.id); - } else if (e.key == 'ArrowUp' || e.key == 'ArrowLeft') { + } else if (e.key == 'ArrowUp') { next = elements[index == 0 ? elements.length - 1 : index - 1]; setSelectedLink(next.id); - } else if (e.key == 'ArrowDown' || e.key == 'ArrowRight') { + } else if (e.key == 'ArrowDown') { next = elements[index == elements.length - 1 ? 0 : index + 1]; setSelectedLink(next.id); } From 45c7fd326d0bffeb63ae38a754f781e2b0741b53 Mon Sep 17 00:00:00 2001 From: flakeed Date: Fri, 14 Apr 2023 20:39:29 +0000 Subject: [PATCH 2/2] update move cursor --- imports/cyto-react-links-card.tsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/imports/cyto-react-links-card.tsx b/imports/cyto-react-links-card.tsx index 7894e134..21b83b3c 100644 --- a/imports/cyto-react-links-card.tsx +++ b/imports/cyto-react-links-card.tsx @@ -218,13 +218,18 @@ export const CytoReactLinksCard = React.memo(({ useEffect(() => { inputRef.current.focus(); - }) + }, []); const selectLink = useCallback((linkId) => { setSelectedLink((prevLinkId) => prevLinkId == linkId ? 0 : linkId); }, []); - useHotkeys('up,down', e => { + useHotkeys('up,right,down,left', e => { + const searchInput = document.activeElement; + if (searchInput instanceof HTMLInputElement || searchInput instanceof HTMLTextAreaElement) { + return; + } + e.preventDefault(); e.stopPropagation(); let index = elements.findIndex(e => e.id == selectedLink); @@ -234,10 +239,10 @@ export const CytoReactLinksCard = React.memo(({ let next = elements[index]; if (!selectedLink) { setSelectedLink(next.id); - } else if (e.key == 'ArrowUp') { + } else if (e.key == 'ArrowUp' || e.key == 'ArrowLeft') { next = elements[index == 0 ? elements.length - 1 : index - 1]; setSelectedLink(next.id); - } else if (e.key == 'ArrowDown') { + } else if (e.key == 'ArrowDown' || e.key == 'ArrowRight') { next = elements[index == elements.length - 1 ? 0 : index + 1]; setSelectedLink(next.id); }