File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -53,12 +53,9 @@ export default function Dialog(props: IDialogPropTypes) {
53
53
54
54
// ========================= Events =========================
55
55
function onDialogVisibleChanged ( newVisible : boolean ) {
56
+ // Try to focus
56
57
if ( newVisible ) {
57
- // Try to focus
58
- if ( ! contains ( wrapperRef . current , document . activeElement ) ) {
59
- lastOutSideActiveElementRef . current = document . activeElement as HTMLElement ;
60
- contentRef . current ?. focus ( ) ;
61
- }
58
+ contentRef . current ?. focus ( ) ;
62
59
} else {
63
60
// Clean up scroll bar & focus back
64
61
setAnimatedVisible ( false ) ;
@@ -127,10 +124,17 @@ export default function Dialog(props: IDialogPropTypes) {
127
124
}
128
125
}
129
126
127
+ function saveLastOutSideActiveElementRef ( ) {
128
+ if ( ! contains ( wrapperRef . current , document . activeElement ) ) {
129
+ lastOutSideActiveElementRef . current = document . activeElement as HTMLElement ;
130
+ }
131
+ }
132
+
130
133
// ========================= Effect =========================
131
134
useEffect ( ( ) => {
132
135
if ( visible ) {
133
136
setAnimatedVisible ( true ) ;
137
+ saveLastOutSideActiveElementRef ( ) ;
134
138
}
135
139
} , [ visible ] ) ;
136
140
You can’t perform that action at this time.
0 commit comments