11import { useDOMRef } from '@react-spectrum/utils' ;
2- import { DismissButton , FocusScope } from 'react-aria' ;
3- import { forwardRef , ReactElement , useMemo } from 'react' ;
2+ import { DismissButton , FocusScope , useFocusManager } from 'react-aria' ;
3+ import { forwardRef , ReactElement , useEffect , useMemo , useState } from 'react' ;
44import { useDialog , useMessageFormatter , AriaDialogProps } from 'react-aria' ;
55import { DOMRef } from '@react-types/shared' ;
66
@@ -149,12 +149,12 @@ export const Dialog = forwardRef(function Dialog(
149149 return < DialogContent key = "content" { ...props } ref = { ref } /> ;
150150 } , [ props , ref ] ) ;
151151
152- if ( context . type === 'panel' || ! isEntered ) {
153- return content ;
154- }
155-
156152 return (
157- < FocusScope contain restoreFocus autoFocus >
153+ < FocusScope
154+ restoreFocus
155+ autoFocus = { isEntered }
156+ contain = { isEntered && context . type !== 'panel' }
157+ >
158158 { content }
159159 </ FocusScope >
160160 ) ;
@@ -177,6 +177,8 @@ const DialogContent = forwardRef(function DialogContent(
177177 ...otherProps
178178 } = props ;
179179
180+ const [ isCloseDisabled , setIsCloseDisabled ] = useState ( true ) ;
181+
180182 size = sizeMap [ size . toUpperCase ( ) ] || size ;
181183
182184 const styles : Styles = extractStyles ( otherProps , STYLES_LIST ) ;
@@ -196,6 +198,15 @@ const DialogContent = forwardRef(function DialogContent(
196198 dismissButton = < DismissButton onDismiss = { onDismiss } /> ;
197199 }
198200
201+ const focusManager = useFocusManager ( ) ;
202+
203+ useEffect ( ( ) => {
204+ setTimeout ( ( ) => {
205+ focusManager ?. focusFirst ( ) ;
206+ setIsCloseDisabled ( false ) ;
207+ } ) ;
208+ } , [ ] ) ;
209+
199210 // let hasHeader = useHasChild('[data-id="Header"]', domRef);
200211 // let hasFooter = useHasChild('[data-id="Footer"]', domRef);
201212
@@ -261,9 +272,9 @@ const DialogContent = forwardRef(function DialogContent(
261272 < SlotProvider slots = { slots } >
262273 { isDismissable && (
263274 < Button
275+ isDisabled = { isCloseDisabled }
264276 qa = "ModalCloseButton"
265277 type = "neutral"
266- tabIndex = "-1"
267278 styles = { CLOSE_BUTTON_STYLES }
268279 icon = { closeIcon || < CloseIcon /> }
269280 label = { formatMessage ( 'dismiss' ) }
0 commit comments