refactor: correctly getActiveScope when on modal

This commit is contained in:
Timothy Z. 2026-04-29 16:37:51 +03:00
parent b7655e658f
commit 7c3f79ac1a

View file

@ -3,11 +3,13 @@
import { useEffect, useRef } from 'react';
import { useGamepad } from '../GamepadContext';
const FOCUSABLE = '[tabindex]';
const FOCUSABLE = '[tabindex]:not([data-focus-guard])';
const getActiveScope = (fallback: HTMLDivElement | null): HTMLElement | null => {
const modal = document.querySelector<HTMLElement>('.modals-container');
if (modal && modal.children.length > 0) return modal;
const modals = document.querySelectorAll<HTMLElement>('.modals-container');
for (const modal of modals) {
if (modal.children.length > 0) return modal;
}
const dropdown = fallback?.querySelector<HTMLElement>('[class*="dropdown"][class*="open"]');
if (dropdown) return dropdown;