fix(17): IN-01 pull focus back into dialog when activeElement escapes
This commit is contained in:
@@ -43,6 +43,16 @@ export function useFocusTrap(
|
|||||||
const first = focusable[0];
|
const first = focusable[0];
|
||||||
const last = focusable[focusable.length - 1];
|
const last = focusable[focusable.length - 1];
|
||||||
|
|
||||||
|
// Containment guard (IN-01): if focus has somehow landed outside the dialog
|
||||||
|
// (programmatic focus, browser quirk), neither boundary condition below
|
||||||
|
// matches and Tab would walk background content. Pull focus back to the
|
||||||
|
// first focusable instead of relying on a boundary-only trap.
|
||||||
|
if (!dialogRef.current.contains(document.activeElement)) {
|
||||||
|
e.preventDefault();
|
||||||
|
first.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (e.shiftKey) {
|
if (e.shiftKey) {
|
||||||
// Shift+Tab: if on first element, wrap to last
|
// Shift+Tab: if on first element, wrap to last
|
||||||
if (document.activeElement === first) {
|
if (document.activeElement === first) {
|
||||||
|
|||||||
Reference in New Issue
Block a user