Skip to content

Commit 69e5101

Browse files
committed
fix(Dialog): panel type * 7
1 parent 41e9f2f commit 69e5101

File tree

4 files changed

+13
-10
lines changed

4 files changed

+13
-10
lines changed

src/components/overlays/Dialog/Dialog.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,7 @@ export const Dialog = forwardRef(function Dialog(
150150
}, [props, ref]);
151151

152152
return (
153-
<FocusScope
154-
restoreFocus
155-
autoFocus={isEntered}
156-
contain={isEntered && context.type !== 'panel'}
157-
>
153+
<FocusScope restoreFocus contain={isEntered && context.type !== 'panel'}>
158154
{content}
159155
</FocusScope>
160156
);
@@ -202,11 +198,15 @@ const DialogContent = forwardRef(function DialogContent(
202198

203199
// Focus the first focusable element in the dialog when it opens
204200
useEffect(() => {
205-
setTimeout(() => {
206-
focusManager?.focusFirst();
207-
setIsCloseDisabled(false);
208-
});
209-
}, []);
201+
if (contextProps.isOpen) {
202+
setTimeout(() => {
203+
focusManager?.focusFirst();
204+
setIsCloseDisabled(false);
205+
});
206+
} else {
207+
setIsCloseDisabled(true);
208+
}
209+
}, [contextProps.isOpen]);
210210

211211
// let hasHeader = useHasChild('[data-id="Header"]', domRef);
212212
// let hasFooter = useHasChild('[data-id="Footer"]', domRef);

src/components/overlays/Dialog/DialogContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export function DialogContainer(props: CubeDialogContainerProps) {
6464
type,
6565
onClose: onDismiss,
6666
isDismissable,
67+
isOpen,
6768
};
6869

6970
return (

src/components/overlays/Dialog/DialogTrigger.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ function DialogTriggerBase(props) {
309309
type,
310310
onClose,
311311
isDismissable,
312+
isOpen: state.isOpen,
312313
...dialogProps,
313314
};
314315

src/components/overlays/Dialog/context.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface DialogContextValue extends HTMLAttributes<HTMLElement> {
1111
| 'panel';
1212
isDismissable?: boolean;
1313
onClose?: (arg?: string) => void;
14+
isOpen?: boolean;
1415
}
1516

1617
export const DialogContext = createContext<DialogContextValue | null>({});

0 commit comments

Comments
 (0)