Skip to content

Commit

Permalink
[docs] Improve table of contents cmd+click (#18765)
Browse files Browse the repository at this point in the history
  • Loading branch information
Janpot authored and oliviertassinari committed Dec 10, 2019
1 parent 3199e0d commit 1bb4ba0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 13 additions & 1 deletion docs/src/modules/components/AppTableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,19 @@ export default function AppTableOfContents(props) {
// Corresponds to 10 frames at 60 Hz
useThrottledOnScroll(itemsServer.length > 0 ? findActiveIndex : null, 166);

const handleClick = hash => () => {
const handleClick = hash => event => {
// Ignore click for new tab/new window behavior
if (
event.defaultPrevented ||
event.button !== 0 || // ignore everything but left-click
event.metaKey ||
event.ctrlKey ||
event.altKey ||
event.shiftKey
) {
return;
}

// Used to disable findActiveIndex if the page scrolls due to a click
clickedRef.current = true;
unsetClickedRef.current = setTimeout(() => {
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/components/MarkdownLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export async function handleEvent(event, as) {
event.button !== 0 || // ignore everything but left-click
event.metaKey ||
event.ctrlKey ||
event.shiftKey ||
(event.nativeEvent && event.nativeEvent.which === 2)
event.altKey ||
event.shiftKey
) {
return;
}
Expand Down

0 comments on commit 1bb4ba0

Please sign in to comment.