Skip to content
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

Merged
merged 5 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class ZeroMd extends HTMLElement {
// Scroll to selected element
goto(id) {
if (id) {
const el = this.root.getElementById(id.substring(1))
const el = this.root.querySelector(id)
if (el) {
el.scrollIntoView()
}
Expand Down
22 changes: 22 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ describe('unit tests', () => {
assert(f.scrollTop > 0)
})

it('scrolls to element if zero-md used in no-shadow mode', async () => {
location.hash = 'tamen-et-veri'
f = add(
`<div style="height:200px;overflow:hidden;"><zero-md src="fixture.md" no-shadow></zero-md></div>`
)
await sleep(500)
assert(f.scrollTop > 0)
})

it('hijacks same-doc hash links and scrolls id into view', async () => {
f = add(
`<div style="height:200px;overflow:hidden;"><zero-md src="fixture.md" manual-render></zero-md></div>`
Expand All @@ -337,6 +346,19 @@ describe('unit tests', () => {
assert(f.scrollTop > 0)
assert(location.hash === '#tamen-et-veri')
})

it('hijacks same-doc hash links and scrolls id into view in no-shadow mode', async () => {
f = add(
`<div style="height:200px;overflow:hidden;"><zero-md src="fixture.md" manual-render no-shadow></zero-md></div>`
)
const el = f.querySelector('zero-md')
await el.render()
const a = document.querySelector('a[href="#tamen-et-veri"]')
a.click()
await sleep(50)
assert(f.scrollTop > 0)
assert(location.hash === '#tamen-et-veri')
})
})

describe('Mutation Observer tests', () => {
Expand Down