-
-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix/no shadow dom scrolling #83
Conversation
Thanks for your PR! The test looks good. As for the solution, I think we can just no-op the Lines 151 to 158 in 5a627f2
We can just no-op it: if (id && !this.hasAttribute('no-shadow') { ... } Which I think should resolve the problem. |
Let me know if you're ok with making this change - happy to merge it in if the tests pass! |
Thanks for the suggestion, I will try it. I think this change is okay. It is annoying that html works such that
Thanks for the review ♥ |
sorry, I don't quite understand your suggested change. I understood it to be: goto(id) {
if (id && !this.hasAttribute('no-shadow')) {
const el = this.root.getElementById(id.substring(1))
if (el) {
el.scrollIntoView()
}
}
} However, with this code: if the element is in light-DOM, there is simply no scroll. Thus, the tests fail. I may have misunderstood your request. For now, I changed the equality a little so it's more obvious what's going on. Let me know if you have any further suggestions. Otherwise, this passes tests. |
Hey you understood it right - my bad, just realised my suggestion won't work. Your original fix works, but I thought perhaps it'll be better to refactor the goto(id) {
let el
try {
el = this.root.querySelector(id)
} catch {}
if (el) el.scrollIntoView()
} WDYT? If you feel it's ok, if you could commit the change I'll then merge this in. |
Hi, thanks for the update. One thing I was missing is that: I did not realise that it was default browser behaviour to scroll to hashlinks, i.e., that Thanks for your code suggestion. I have changed the fix to be very simple: simply replace One final remark is that: if you click a link outside the shadow-DOM, it does not navigate to that header. But, that makes sense why. e.g., <a href="#basic-usage">go to basic usage</a>
<zero-md src="https://raw.githubusercontent.com/zerodevx/zero-md/master/README.md"></zero-md> does not work. The tests pass. |
LGTM - Thanks for your contribution! 🙏 |
closes #82
I do not really like the implementation of this fix. It is not very simply written.
However, I could not think how to better do it.
Perhaps, we could use
this.hasAttribute('no-shadow')
to check for shadow DOM, then use eitherthis.root
ordocument
based on result. This would be more code, but perhaps more understandable of why it is happening.