mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-11-06 12:52: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
@@ -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