🚸(frontend) allow opening "interlinks" with ctrl/command/middle mouse

Links to other pages created through the "@" shortcut are not actual
anchor (`<a>`) elements seemingly due to conflicts with lower-lvl
code, noticeably when drag&dropping the elements.

So those "links" are actually span and we must handle the
"link behavior" ourselves.

This adds more usual "link behavior" to thoses, allowing users to
ctrl+click, command+click, shift+click and middle-mouse click to
interact with the links and open them in a new tab or new window.

Signed-off-by: Emmanuel Pelletier <manu@habite.la>
This commit is contained in:
Emmanuel Pelletier 2026-04-03 14:38:46 +02:00 committed by Anthony LC
parent be38e68dd5
commit 4dcf752ff9
No known key found for this signature in database
2 changed files with 23 additions and 1 deletions

View file

@ -6,6 +6,10 @@ and this project adheres to
## [Unreleased]
### Added
- 🚸(frontend) allow opening "@page" links with ctrl/command/middle-mouse click
## [v4.8.5] - 2026-04-03
### Added

View file

@ -124,10 +124,27 @@ export const LinkSelected = ({
const { emoji, titleWithoutEmoji } = getEmojiAndTitle(title);
const router = useRouter();
const href = `/docs/${docId}/`;
const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
e.preventDefault();
void router.push(`/docs/${docId}/`);
// If ctrl or command is pressed, it opens a new tab. If shift is pressed, it opens a new window
if (e.metaKey || e.ctrlKey || e.shiftKey) {
window.open(href, '_blank');
return;
}
void router.push(href);
};
// This triggers on middle-mouse click
const handleAuxClick = (e: React.MouseEvent<HTMLDivElement>) => {
if (e.button !== 1) {
return;
}
e.preventDefault();
e.stopPropagation();
window.open(href, '_blank');
};
return (
@ -135,6 +152,7 @@ export const LinkSelected = ({
as="span"
className="--docs--interlinking-link-inline-content"
onClick={handleClick}
onAuxClick={handleAuxClick}
draggable="false"
$css={css`
display: inline;