Skip to content

Commit

Permalink
Improve current solution, allow selecting text
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Oct 3, 2024
1 parent 51306c9 commit 3d175b4
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions website/src/components/APITable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 3d175b4

Please sign in to comment.