mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-24 23:51: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
@@ -1,3 +1,5 @@
|
||||
import { isClaimedKey } from '../accessibility/keyboard'
|
||||
|
||||
function asElement(target: EventTarget | null | undefined): HTMLElement | undefined {
|
||||
if (target && (target as Node).nodeType === 1)
|
||||
return target as HTMLElement
|
||||
@@ -16,7 +18,7 @@ function editable(target: HTMLElement): boolean {
|
||||
}
|
||||
|
||||
export function acceptsHotkey(event: KeyboardEvent, fallback: Document): boolean {
|
||||
if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.isComposing || event.keyCode === 229)
|
||||
if (isClaimedKey(event) || event.altKey || event.ctrlKey || event.metaKey || event.shiftKey || event.isComposing || event.keyCode === 229)
|
||||
return false
|
||||
const doc = eventDocument(event, fallback)
|
||||
let active = asElement(doc.activeElement)
|
||||
@@ -26,5 +28,12 @@ export function acceptsHotkey(event: KeyboardEvent, fallback: Document): boolean
|
||||
return false
|
||||
// The composed path exposes an editable descendant behind a retargeted shadow host.
|
||||
const first = asElement(event.composedPath?.()[0]) || asElement(event.target)
|
||||
const enter = event.key === 'Enter' || event.code === 'Enter' || event.code === 'NumpadEnter'
|
||||
const activation = enter || event.key === ' ' || event.code === 'Space'
|
||||
if (activation) {
|
||||
const selector = `button,summary,[role="button"],[role="switch"]${enter ? ',a[href]' : ''}`
|
||||
if (first?.closest?.(selector) || active?.closest?.(selector))
|
||||
return false
|
||||
}
|
||||
return !first || !editable(first)
|
||||
}
|
||||
Reference in new issue
Block a user