From 3d175b4968be3e2d227e4ee5a28663d17998bcf1 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 3 Oct 2024 14:05:49 +0200 Subject: [PATCH] Improve current solution, allow selecting text --- website/src/components/APITable/index.tsx | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/website/src/components/APITable/index.tsx b/website/src/components/APITable/index.tsx index 57b82acf1796..91ef2d509caa 100644 --- a/website/src/components/APITable/index.tsx +++ b/website/src/components/APITable/index.tsx @@ -58,18 +58,13 @@ function APITableRow( tabIndex={0} ref={history.location.hash === anchor ? ref : undefined} onClick={(e) => { - const isClickOnCodeName = - (e.target as HTMLElement).tagName.toUpperCase() === 'CODE'; - const isLinkClick = - (e.target as HTMLElement).tagName.toUpperCase() === 'A'; - if (!isLinkClick) { - /** - * Don't navigate if the user clicks on the name - * to let user doubleclick on the name for highlight - */ - if (!isClickOnCodeName) { - history.push(anchor); - } + const isTDClick = + (e.target as HTMLElement).tagName.toUpperCase() === 'TD'; + const hasSelectedText = !!window.getSelection()?.toString(); + + const shouldNavigate = isTDClick && !hasSelectedText; + if (shouldNavigate) { + history.push(anchor); } }} onKeyDown={(e: React.KeyboardEvent) => {