Hotfix for smooth scroll not working on anchors — https://github.com/hotwired/turbo/issues/1255
This commit is contained in:
parent
1105cc947f
commit
a17056fb17
@ -42,6 +42,7 @@
|
||||
background: none;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
|
||||
svg {
|
||||
height: 16px;
|
||||
width: 16px;
|
||||
|
||||
@ -31,3 +31,33 @@ export * from "./controllers.js";
|
||||
shouldPreserveScroll = false;
|
||||
});
|
||||
})();
|
||||
|
||||
/* fix for https://github.com/hotwired/turbo/issues/1255 */
|
||||
(() => {
|
||||
const markHashLinks = (root: ParentNode): void => {
|
||||
root.querySelectorAll<HTMLAnchorElement>('a[href^="#"]').forEach((link) => {
|
||||
link.dataset.turbo = "false";
|
||||
});
|
||||
};
|
||||
|
||||
markHashLinks(document);
|
||||
|
||||
const observer = new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
mutation.addedNodes.forEach((node) => {
|
||||
if (!(node instanceof Element)) return;
|
||||
|
||||
if (node instanceof HTMLAnchorElement && node.matches('a[href^="#"]')) {
|
||||
node.dataset.turbo = "false";
|
||||
}
|
||||
|
||||
markHashLinks(node);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
observer.observe(document.documentElement, {
|
||||
childList: true,
|
||||
subtree: true,
|
||||
});
|
||||
})();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user