Merge pull request #251 from linked-danis/pr5-scrollintoview

This commit is contained in:
Simon
2026-03-16 18:45:19 +08:00
committed by GitHub

View File

@@ -213,14 +213,18 @@ export async function selectOptionElement(selectElement: HTMLSelectElement, opti
await waitFor(0.1) // Wait to ensure change event processing completes await waitFor(0.1) // Wait to ensure change event processing completes
} }
interface ScrollableElement extends HTMLElement {
scrollIntoViewIfNeeded?: (centerIfNeeded?: boolean) => void
}
export async function scrollIntoViewIfNeeded(element: HTMLElement) { export async function scrollIntoViewIfNeeded(element: HTMLElement) {
const el = element as any const el = element as ScrollableElement
if (el.scrollIntoViewIfNeeded) { if (typeof el.scrollIntoViewIfNeeded === 'function') {
el.scrollIntoViewIfNeeded() el.scrollIntoViewIfNeeded()
// await waitFor(0.5) // Animation playback // await waitFor(0.5) // Animation playback
} else { } else {
// @todo visibility check // @todo visibility check
el.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'nearest' }) element.scrollIntoView({ behavior: 'auto', block: 'center', inline: 'nearest' })
// await waitFor(0.5) // Animation playback // await waitFor(0.5) // Animation playback
} }
} }