feat(modal): exclude close button from focus trap in modal

This commit is contained in:
Nawaz Dhandala
2026-01-26 19:43:07 +00:00
parent dd996539bc
commit 0bdf74cab2

View File

@@ -66,9 +66,9 @@ const Modal: FunctionComponent<ComponentProps> = (
useEffect(() => {
const modal: HTMLDivElement | null = modalRef.current;
if (modal) {
// Focus the first focusable element in the modal
// Focus the first focusable element in the modal, excluding the close button
const focusableElements: NodeListOf<Element> = modal.querySelectorAll(
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
'button:not([data-testid="close-button"]), [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
);
const firstFocusable: HTMLElement | undefined = focusableElements[0] as
| HTMLElement