Skip to content
Snippets Groups Projects
Commit be270c26 authored by David Smadja's avatar David Smadja
Browse files

Allow navigation using hash link from Bill

parent 78016e9e
No related branches found
No related tags found
No related merge requests found
......@@ -5,11 +5,21 @@
let container: HTMLDivElement
const scrollToAnchor = (hash: string, shadowRoot: ShadowRoot) => {
if (!hash) return
const id = hash.substring(1) // Enlève le #
const element = shadowRoot.getElementById(id)
if (element) {
element.scrollIntoView({ behavior: "smooth" })
}
}
$effect(() => {
if (!container || !billHTML) return
if (!container.shadowRoot) {
const shadow = container.attachShadow({ mode: "open" });
const shadow = container.attachShadow({ mode: "open" })
// Crée un conteneur position:relative dans le Shadow DOM
shadow.innerHTML = `
......@@ -26,11 +36,25 @@
}
</style>
<div class="content-wrapper">${billHTML}</div>
`;
`
scrollToAnchor(window.location.hash, shadow)
shadow.addEventListener("click", (e) => {
const link = (e.target as HTMLElement).closest('a[href^="#"]')
if (link) {
e.preventDefault()
const hash = link.getAttribute("href")
if (hash) {
// Met à jour l'URL du navigateur
window.history.pushState(null, "", hash)
scrollToAnchor(hash, shadow)
}
}
})
} else {
// Met à jour seulement le contenu, pas la structure
const wrapper = container.shadowRoot!.querySelector('.content-wrapper');
if (wrapper) wrapper.innerHTML = billHTML;
const wrapper = container.shadowRoot!.querySelector(".content-wrapper")
if (wrapper) wrapper.innerHTML = billHTML
}
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment