Closed alifeee closed 1 year ago
@alifeee Hi! I just saw your sponsorship - much appreciated, thank you! 🙏
A bit of background regarding this issue - native browser behaviour performs page scroll to an element id in 2 areas:
https://example.com/#header-id
)<a href="#header-id">link</a>
This however doesn't work in the context of a custom element, hence the need to shim it (with the goto()
function) in this project.
Nice catch that this doesn't work when no-shadow
is used. Originally, no-shadow
is a bit "experimental" - most of the time <zero-md>
is intended to work within its own sandbox (the shadow dom). It's a simple enough fix I think. I'll add comments to your PR and see if we can take it from there.
Thanks once again!
You have made a good library! It aligns to my opinions regarding simplicity and web content well.
You may see by my other issue (#84) why I am using no-shadow
. I would like to use the shadow DOM, but it seems libraries like Mermaid/AnchorJS just don't work with it, currently. I would prefer to use the shadow DOM, it is a nice concept and I like it.
Thanks for the quick comment. :)
Working example:
Broken example
The difference is that
no-shadow
is provided to the<zero-md>
element.Expected behaviour:
go to
https://URL#basic-usage
. Page should scroll to that heading.Actual behaviour
console error:
Environment
I am using Firefox.
Code
The problem is with the
goto
function.https://github.com/zerodevx/zero-md/blob/5a627f2a8f605efbc108ba7f3866eb910de9cf20/src/index.js#L151-L158
this.root
does not havegetElementById
ifno-shadow
is true.this.root
is set in theconstructor()
function:https://github.com/zerodevx/zero-md/blob/5a627f2a8f605efbc108ba7f3866eb910de9cf20/src/index.js#L55
The issue appears to be because
getElementById
is only defined on thedocument
object. See MDN web docs.