From 7f6472a74d9ddab664b3c68aa93fff10fdd0ab50 Mon Sep 17 00:00:00 2001 From: Flix Date: Thu, 3 Oct 2024 19:22:59 +0700 Subject: [PATCH] fix(website): APITable component should navigate to anchor less agressively (#10534) Co-authored-by: Flix Co-authored-by: sebastien --- website/src/components/APITable/index.tsx | 9 ++++++--- website/src/components/APITable/styles.module.css | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/website/src/components/APITable/index.tsx b/website/src/components/APITable/index.tsx index db94ae6fb649..91ef2d509caa 100644 --- a/website/src/components/APITable/index.tsx +++ b/website/src/components/APITable/index.tsx @@ -58,9 +58,12 @@ function APITableRow( tabIndex={0} ref={history.location.hash === anchor ? ref : undefined} onClick={(e) => { - const isLinkClick = - (e.target as HTMLElement).tagName.toUpperCase() === 'A'; - if (!isLinkClick) { + const isTDClick = + (e.target as HTMLElement).tagName.toUpperCase() === 'TD'; + const hasSelectedText = !!window.getSelection()?.toString(); + + const shouldNavigate = isTDClick && !hasSelectedText; + if (shouldNavigate) { history.push(anchor); } }} diff --git a/website/src/components/APITable/styles.module.css b/website/src/components/APITable/styles.module.css index 4048c94243d2..e22474dacef2 100644 --- a/website/src/components/APITable/styles.module.css +++ b/website/src/components/APITable/styles.module.css @@ -20,3 +20,7 @@ cursor: pointer; transition: box-shadow 0.2s; } + +.apiTable code { + cursor: text; +}