mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-10 12:46:15 -08:00
10 lines
473 B
TypeScript
10 lines
473 B
TypeScript
/** Restore the same focused descendant after DOM reparenting. */
|
|
export function captureMovedFocus(root: HTMLElement): () => void {
|
|
const focused = root.ownerDocument?.activeElement as HTMLElement | null | undefined
|
|
const inside = focused && root.contains(focused)
|
|
return () => {
|
|
if (inside && focused.isConnected && root.contains(focused) && focused.ownerDocument.activeElement === focused.ownerDocument.body)
|
|
focused.focus({ preventScroll: true })
|
|
}
|
|
}
|