mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-04 03:42:26 +00:00
Improve video modal accessibility handling
This commit is contained in:
1 parent
eef0a50f24
commit
16cb69021d
6 files changed
+228
-26
No files matched your search
@@ -461,7 +461,7 @@ export class VideoModal {
|
||||
this.dispatch("creator:navigate", { video: this.activeVideo });
|
||||
}
|
||||
|
||||
open(video) {
|
||||
open(video, options = {}) {
|
||||
this.activeVideo = video || null;
|
||||
if (!this.playerModal) {
|
||||
return;
|
||||
@@ -471,7 +471,9 @@ export class VideoModal {
|
||||
this.playerModal.classList.remove("hidden");
|
||||
this.document.body.classList.add("modal-open");
|
||||
this.document.documentElement.classList.add("modal-open");
|
||||
this.modalAccessibility?.activate();
|
||||
const triggerElement =
|
||||
options && typeof options === "object" ? options.triggerElement : null;
|
||||
this.modalAccessibility?.activate({ triggerElement });
|
||||
if (this.scrollRegion) {
|
||||
this.scrollRegion.scrollTop = 0;
|
||||
}
|
||||
|
||||
@@ -19,6 +19,15 @@ const scheduleMicrotask =
|
||||
? queueMicrotask
|
||||
: (callback) => Promise.resolve().then(callback);
|
||||
|
||||
function isElement(node) {
|
||||
return (
|
||||
!!node &&
|
||||
typeof node === "object" &&
|
||||
typeof node.nodeType === "number" &&
|
||||
node.nodeType === 1
|
||||
);
|
||||
}
|
||||
|
||||
function isFocusable(element) {
|
||||
if (!element) {
|
||||
return false;
|
||||
@@ -130,13 +139,22 @@ export function createModalAccessibility({ root, panel, backdrop, document: prov
|
||||
onRequestClose?.(event);
|
||||
};
|
||||
|
||||
const activate = () => {
|
||||
const activate = ({ triggerElement } = {}) => {
|
||||
if (active) {
|
||||
return;
|
||||
}
|
||||
active = true;
|
||||
const activeElement = doc.activeElement;
|
||||
previousFocus = activeElement instanceof Element ? activeElement : null;
|
||||
const hasDocContains = typeof doc.contains === "function";
|
||||
const normalizedTrigger =
|
||||
isElement(triggerElement) && (!hasDocContains || doc.contains(triggerElement))
|
||||
? triggerElement
|
||||
: null;
|
||||
if (normalizedTrigger) {
|
||||
previousFocus = normalizedTrigger;
|
||||
} else {
|
||||
previousFocus = isElement(activeElement) ? activeElement : null;
|
||||
}
|
||||
doc.addEventListener("keydown", keydownListener, true);
|
||||
root.addEventListener("click", clickListener);
|
||||
if (backdrop && backdrop !== root) {
|
||||
|
||||
Reference in new issue
Block a user