From f88e15fafd7ee22006ded48ced7b2d2f77577316 Mon Sep 17 00:00:00 2001 From: Flix Date: Sat, 28 Sep 2024 22:46:11 +0700 Subject: [PATCH 1/3] feat(apitable): support for highlight APIs name table --- website/src/components/APITable/index.tsx | 10 +++++++++- website/src/components/APITable/styles.module.css | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/website/src/components/APITable/index.tsx b/website/src/components/APITable/index.tsx index db94ae6fb649..57b82acf1796 100644 --- a/website/src/components/APITable/index.tsx +++ b/website/src/components/APITable/index.tsx @@ -58,10 +58,18 @@ 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) { - history.push(anchor); + /** + * Don't navigate if the user clicks on the name + * to let user doubleclick on the name for highlight + */ + if (!isClickOnCodeName) { + history.push(anchor); + } } }} onKeyDown={(e: React.KeyboardEvent) => { 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; +} From 51306c91c6ff6dec9311b85e31e5b80a1f581fa8 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 3 Oct 2024 13:04:01 +0200 Subject: [PATCH 2/3] empty From 3d175b4968be3e2d227e4ee5a28663d17998bcf1 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 3 Oct 2024 14:05:49 +0200 Subject: [PATCH 3/3] 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) => {