Skip to content

Commit

Permalink
refactor(PrimaryModalShell): focus container with ref, get rid of use…
Browse files Browse the repository at this point in the history
…Effect
  • Loading branch information
olafsulich committed Oct 30, 2024
1 parent 191c3f9 commit 0fe1182
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/

import {useRef, useEffect, ReactNode} from 'react';
import {ReactNode} from 'react';

import {ModalComponent} from 'Components/ModalComponent';

Expand All @@ -38,14 +38,6 @@ export const PrimaryModalShell = ({
onClose,
onBgClick,
}: PrimaryModalShellProps) => {
const modalRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (isShown) {
modalRef.current?.focus();
}
}, [isShown]);

return (
<div
id="modals"
Expand All @@ -54,7 +46,7 @@ export const PrimaryModalShell = ({
aria-modal="true"
aria-label={title}
tabIndex={-1}
ref={modalRef}
ref={ref => isShown && ref?.focus()}
>
<ModalComponent isShown={isShown} onClosed={onClose} onBgClick={onBgClick} data-uie-name={dataUieName}>
{isShown && children}
Expand Down

0 comments on commit 0fe1182

Please sign in to comment.