fix #868 - prevent "copy link" styling/behavior when a link is used inside a heading

This commit is contained in:
James Fenn
2024-01-21 02:35:49 -05:00
parent 8002522a7a
commit 36a5b9cf50
3 changed files with 34 additions and 6 deletions

View File

@@ -154,3 +154,7 @@ This is regular text.
2. Padded sub-item 2
3. List item 3
# Heading `with a code snippet` inside of it
# Heading [with a link](https://example.com) inside of it

View File

@@ -31,6 +31,10 @@ import style from "./heading-link.module.scss";
) as HTMLTemplateElement;
function handleClick(e: Event) {
if ((e.target as HTMLElement).tagName === "A") {
return;
}
const target = e.currentTarget as HTMLElement;
const headingAnchorEl = target.hasAttribute("data-heading-anchor")
? target

View File

@@ -87,6 +87,17 @@
}
}
// If the heading contains an <a> which is hovered,
// click will follow the anchor href, so the "Copy link"
// button should not be displayed
@supports selector(:has(*)) {
:global(.heading-linked):has(a:hover, a:focus) {
.headingLink {
opacity: 0 !important;
}
}
}
.headingLinkContainer:focus-visible .headingLink {
outline: var(--heading-link_outline-width) solid var(--heading-link_outline-color);
}
@@ -116,13 +127,17 @@
--heading_background_outline-width: var(--border-width_focus);
}
@supports selector(:has(*)) {
:global(.heading-linked):hover,
:global(.heading-linked):focus-within,
:global(.heading-linked):has(.headingLinkContainer:hover) {
// The underline should not be applied if an inner <a> is focused
// as clicking will follow the link, not interact with the heading
&:not(:has(a:hover, a:focus)) {
text-decoration: underline;
}
}
@supports selector(:has(*)) {
:global(.heading-linked):has(.headingLinkContainer:focus-visible) {
&> span {
border-radius: calc(var(--heading_background_corner-radius) - var(--heading_background_padding));
@@ -133,6 +148,11 @@
}
@supports not selector(:has(*)) {
:global(.heading-linked):hover,
:global(.heading-linked):focus-within {
text-decoration: underline;
}
:global(.heading-linked):focus-within {
&> span {
border-radius: calc(var(--heading_background_corner-radius) - var(--heading_background_padding));