Skip to content

Commit

Permalink
modal: Remove elementToFocusOnClose prop. (#1894)
Browse files Browse the repository at this point in the history
  • Loading branch information
stowball authored Dec 3, 2024
1 parent b16fd60 commit c70b445
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/polite-flowers-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@ag.ds-next/react': minor
---

modal: Remove `elementToFocusOnClose` prop.
8 changes: 1 addition & 7 deletions packages/react/src/modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export type ModalProps = ModalDialogProps & {
export const Modal: FunctionComponent<ModalProps> = ({
actions,
children,
elementToFocusOnClose,
isOpen = false,
onClose,
onDismiss,
Expand Down Expand Up @@ -48,12 +47,7 @@ export const Modal: FunctionComponent<ModalProps> = ({
<Fragment>
<LockScroll />
<ModalCover ref={modalContainerRef}>
<ModalDialog
actions={actions}
elementToFocusOnClose={elementToFocusOnClose}
onClose={closeHandler}
title={title}
>
<ModalDialog actions={actions} onClose={closeHandler} title={title}>
{children}
</ModalDialog>
</ModalCover>
Expand Down
16 changes: 1 addition & 15 deletions packages/react/src/modal/ModalDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { useModalId } from './utils';
export type ModalDialogProps = PropsWithChildren<{
/** The actions to display at the bottom of the modal panel. Typically a `ButtonGroup`. */
actions?: ReactNode;
/** On close of the modal, this element will be focused, rather than the trigger element. */
elementToFocusOnClose?: HTMLElement | null;
/** Function to be called when the 'Close' button is pressed. */
onClose?: () => void;
/** @deprecated use `onClose` instead */
Expand All @@ -28,26 +26,14 @@ const MAX_WIDTH = '45rem'; // 720 px
export const ModalDialog = ({
actions,
children,
elementToFocusOnClose,
onClose,
onDismiss,
title,
}: ModalDialogProps) => {
const closeHandler = getRequiredCloseHandler(onClose, onDismiss);
const { titleId } = useModalId();
return (
<FocusLock
returnFocus={
elementToFocusOnClose
? () => {
// Running focus after focus-lock-react does its cleanup, more info here: https://github.com/theKashey/react-focus-lock#unmounting-and-focus-management
window.setTimeout(() => elementToFocusOnClose.focus(), 0);

return false;
}
: true // Return focus to trigger on close
}
>
<FocusLock returnFocus>
<Stack
aria-labelledby={titleId}
aria-modal="true"
Expand Down

0 comments on commit c70b445

Please sign in to comment.