Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
!shouldFocus ||
!dialog ||
nestedDialogs.find(child =>
Boolean(child.current && !child.current.hidden)
)
) {
return;
}
if (initialFocusRef && initialFocusRef.current) {
initialFocusRef.current.focus({ preventScroll: true });
} else {
const tabbable = getFirstTabbableIn(dialog, true);
const isActive = () => dialog.contains(document.activeElement);
if (tabbable) {
ensureFocus(tabbable, { preventScroll: true, isActive });
} else {
ensureFocus(dialog, { preventScroll: true, isActive });
warning(
dialog.tabIndex === undefined || dialog.tabIndex < 0,
"[reakit/Dialog]",
"It's recommended to have at least one tabbable element inside dialog. The dialog element has been automatically focused.",
"If this is the intended behavior, pass `tabIndex={0}` to the dialog element to disable this warning.",
"See https://reakit.io/docs/dialog/#initial-focus"
);
}
}
}, [dialogRef, nestedDialogs, initialFocusRef, shouldFocus]);
}
nestedDialogs.find(child =>
Boolean(child.current && !child.current.hidden)
)
) {
return;
}
if (initialFocusRef && initialFocusRef.current) {
initialFocusRef.current.focus({ preventScroll: true });
} else {
const tabbable = getFirstTabbableIn(dialog, true);
const isActive = () => dialog.contains(document.activeElement);
if (tabbable) {
ensureFocus(tabbable, { preventScroll: true, isActive });
} else {
ensureFocus(dialog, { preventScroll: true, isActive });
warning(
dialog.tabIndex === undefined || dialog.tabIndex < 0,
"[reakit/Dialog]",
"It's recommended to have at least one tabbable element inside dialog. The dialog element has been automatically focused.",
"If this is the intended behavior, pass `tabIndex={0}` to the dialog element to disable this warning.",
"See https://reakit.io/docs/dialog/#initial-focus"
);
}
}
}, [dialogRef, nestedDialogs, initialFocusRef, shouldFocus]);
}
document.activeElement &&
dialog &&
!dialog.contains(document.activeElement) &&
(isTabbable(document.activeElement) ||
document.activeElement.getAttribute("data-dialog") === "true")
) {
return;
}
const finalFocusEl =
(options.unstable_finalFocusRef &&
options.unstable_finalFocusRef.current) ||
(disclosuresRef.current && disclosuresRef.current[0]);
if (finalFocusEl) {
ensureFocus(finalFocusEl);
} else {
warning(
true,
"[reakit/Dialog]",
"Can't return focus after closing dialog. Either render a disclosure component or provide a `unstable_finalFocusRef` prop.",
"See https://reakit.io/docs/dialog"
);
}
}, [dialogRef, disclosuresRef, shouldFocus]);
}