@@ -9,6 +9,7 @@ let id = 0;
9
9
const ESC = 27 ;
10
10
11
11
export interface IModalProps extends IOverlayProps {
12
+ dontLockFocus ?: boolean ;
12
13
onEsc ?: ( event : KeyboardEvent ) => void ;
13
14
onClose ?: ( ) => void ;
14
15
}
@@ -49,20 +50,28 @@ export class Modal extends Component<IModalProps, IModalState> {
49
50
50
51
for ( let i = 0 ; i < siblings . length ; i ++ ) {
51
52
const sibling = siblings [ i ] as HTMLElement ;
53
+ const sib = sibling as any ;
52
54
53
55
if ( sibling === this . el ) {
54
56
continue ;
55
57
}
56
58
57
- if ( ( sibling as any ) . __modal_lock !== this ) {
59
+ if ( ! sib . __libreact_lock ) {
58
60
continue ;
59
61
}
60
62
61
- delete ( sibling as any ) . __modal_lock ;
62
- ( sibling as any ) . inert = false ;
63
- sibling . style . removeProperty ( 'pointer-events' ) ;
64
- sibling . style . removeProperty ( 'user-select' ) ;
63
+ if ( sib . __libreact_lock . owner !== this ) {
64
+ continue ;
65
+ }
66
+
67
+ const lock = sib . __libreact_lock ;
68
+
69
+ sib . inert = lock . inert ;
70
+ sibling . style . setProperty ( 'pointer-events' , lock . pointerEvents ) ,
71
+ sibling . style . setProperty ( 'user-select' , lock . userSelect ) ,
72
+
65
73
sibling . removeAttribute ( 'aria-hidden' ) ;
74
+ delete sib . __libreact_lock ;
66
75
}
67
76
68
77
// Focus previously active element.
@@ -90,12 +99,24 @@ export class Modal extends Component<IModalProps, IModalState> {
90
99
continue ;
91
100
}
92
101
93
- if ( ( sibling as any ) . __modal_lock ) {
102
+ if ( ( sibling as any ) . __libreact_lock ) {
103
+ continue ;
104
+ }
105
+
106
+ if ( sibling . hasAttribute ( 'aria-hidden' ) ) {
94
107
continue ;
95
108
}
96
109
97
- ( sibling as any ) . __modal_lock = this ;
98
- ( sibling as any ) . inert = true ;
110
+ const sib = sibling as any ;
111
+
112
+ sib . __libreact_lock = {
113
+ owner : this ,
114
+ inert : sib . inert ,
115
+ pointerEvents : sibling . style . getPropertyValue ( 'pointer-events' ) ,
116
+ userSelect : sibling . style . getPropertyValue ( 'user-select' ) ,
117
+ } ;
118
+
119
+ sib . inert = true ;
99
120
sibling . style . setProperty ( 'pointer-events' , 'none' ) ;
100
121
sibling . style . setProperty ( 'user-select' , 'none' ) ;
101
122
sibling . setAttribute ( 'aria-hidden' , 'true' ) ;
@@ -111,17 +132,20 @@ export class Modal extends Component<IModalProps, IModalState> {
111
132
} ;
112
133
113
134
render ( ) {
114
- const { color, time, onClick} = this . props ;
135
+ const { color, dontLockFocus, time, onClick} = this . props ;
136
+ let element = render ( this . props , this . state ) ;
137
+
138
+ if ( ! dontLockFocus ) {
139
+ element = h ( FocusLock , null , element ) ;
140
+ }
115
141
116
142
return h ( Overlay , {
117
143
color,
118
144
time,
119
145
onClick,
120
146
onElement : this . onElement ,
121
147
} ,
122
- h ( FocusLock , null ,
123
- render ( this . props , this . state )
124
- )
148
+ element
125
149
) ;
126
150
}
127
151
}
0 commit comments