mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 18:41:20 -08:00
refactor(core): [CORE-23] complete keyboard controls and focus lifecycle
This commit is contained in:
1 parent
faaa3e8c2d
commit
8ed0a5228c
190 files changed
+53981
-489
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import type { ComponentHost } from '../component/types'
|
||||
import { getScope, isClosing } from '../lifecycle/instance'
|
||||
|
||||
const owned = new WeakSet<HTMLElement>()
|
||||
|
||||
export function focusPlayer(art: Pick<ComponentHost, 'template'>): void {
|
||||
const player = art.template.$player
|
||||
if (isClosing(art) || !player.isConnected)
|
||||
return
|
||||
if (!player.hasAttribute('tabindex')) {
|
||||
player.setAttribute('tabindex', '-1')
|
||||
if (!owned.has(player)) {
|
||||
owned.add(player)
|
||||
getScope(art).add(() => {
|
||||
owned.delete(player)
|
||||
if (player.getAttribute('tabindex') === '-1')
|
||||
player.removeAttribute('tabindex')
|
||||
})
|
||||
}
|
||||
}
|
||||
player.focus({ preventScroll: true })
|
||||
}
|
||||
Reference in new issue
Block a user