@@ -49,6 +49,7 @@ type FocusEventType = 'focus' | 'blur' | 'focuschange' | 'focusvisiblechange';
49
49
50
50
type FocusWithinProps = {
51
51
disabled ?: boolean ,
52
+ onFocusWithin ?: ( e : FocusEvent ) => void ,
52
53
onBlurWithin ?: ( e : FocusEvent ) => void ,
53
54
onFocusWithinChange ?: boolean => void ,
54
55
onFocusWithinVisibleChange ?: boolean => void ,
@@ -57,7 +58,8 @@ type FocusWithinProps = {
57
58
type FocusWithinEventType =
58
59
| 'focuswithinvisiblechange'
59
60
| 'focuswithinchange'
60
- | 'blurwithin' ;
61
+ | 'blurwithin'
62
+ | 'focuswithin' ;
61
63
62
64
/**
63
65
* Shared between Focus and FocusWithin
@@ -239,6 +241,26 @@ function dispatchBlurEvents(
239
241
}
240
242
}
241
243
244
+ function dispatchFocusWithinEvents (
245
+ context : ReactDOMResponderContext ,
246
+ event : ReactDOMResponderEvent ,
247
+ props : FocusWithinProps ,
248
+ state : FocusState ,
249
+ ) {
250
+ const pointerType = state . pointerType ;
251
+ const target = ( ( state . focusTarget : any ) : Element | Document ) || event . target ;
252
+ const onFocusWithin = ( props . onFocusWithin : any ) ;
253
+ if ( isFunction ( onFocusWithin ) ) {
254
+ const syntheticEvent = createFocusEvent (
255
+ context ,
256
+ 'focuswithin' ,
257
+ target ,
258
+ pointerType ,
259
+ ) ;
260
+ context . dispatchEvent ( syntheticEvent , onFocusWithin , DiscreteEvent ) ;
261
+ }
262
+ }
263
+
242
264
function dispatchBlurWithinEvents (
243
265
context : ReactDOMResponderContext ,
244
266
event : ReactDOMResponderEvent ,
@@ -474,6 +496,7 @@ const focusWithinResponderImpl = {
474
496
state . isFocusVisible = isGlobalFocusVisible ;
475
497
dispatchFocusWithinVisibleChangeEvent ( context , props , state , true ) ;
476
498
}
499
+ dispatchFocusWithinEvents ( context , event , props , state ) ;
477
500
break ;
478
501
}
479
502
case 'blur' : {
0 commit comments