Skip to content

Commit

Permalink
Make all modals ignore Close button when placing focus
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Sep 8, 2023
1 parent 9a2176f commit f4efa25
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/components/src/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ import type { ModalProps } from './types';
// Used to count the number of open modals.
let openModalCount = 0;

function focusFirstNonCloseButtonElement( tabbables: HTMLElement[] ) {
return tabbables.find(
// Ignore the `Close` button.
// See: https://github.com/WordPress/gutenberg/issues/54106.
( tabbableNode ) => tabbableNode?.ariaLabel !== 'Close'
);
}

function UnforwardedModal(
props: ModalProps,
forwardedRef: ForwardedRef< HTMLDivElement >
Expand All @@ -47,7 +55,7 @@ function UnforwardedModal(
bodyOpenClassName = 'modal-open',
role = 'dialog',
title = null,
focusOnMount = true,
focusOnMount = focusFirstNonCloseButtonElement,
shouldCloseOnEsc = true,
shouldCloseOnClickOutside = true,
isDismissible = true,
Expand Down

0 comments on commit f4efa25

Please sign in to comment.