File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change @@ -59,8 +59,6 @@ export default function Portal(props: PortalProps) {
59
59
60
60
const [ mergedRender , setMergedRender ] = React . useState ( open ) ;
61
61
62
- useScrollLocker ( autoLock && open ) ;
63
-
64
62
// ====================== Should Render ======================
65
63
React . useEffect ( ( ) => {
66
64
if ( autoDestroy || open ) {
@@ -86,6 +84,15 @@ export default function Portal(props: PortalProps) {
86
84
) ;
87
85
const mergedContainer = innerContainer ?? defaultContainer ;
88
86
87
+ // ========================= Locker ==========================
88
+ useScrollLocker (
89
+ autoLock &&
90
+ open &&
91
+ canUseDom ( ) &&
92
+ ( mergedContainer === defaultContainer ||
93
+ mergedContainer === document . body ) ,
94
+ ) ;
95
+
89
96
// ========================= Render ==========================
90
97
// Do not render when nothing need render
91
98
// When innerContainer is `undefined`, it may not ready since user use ref in the same render
Original file line number Diff line number Diff line change @@ -8,7 +8,9 @@ const UNIQUE_ID = `rc-util-locker-${Date.now()}`;
8
8
9
9
let uuid = 0 ;
10
10
11
- export default function useScrollLocker ( lock ?: boolean ) {
11
+ export default function useScrollLocker (
12
+ lock ?: boolean ,
13
+ ) {
12
14
const mergedLock = ! ! lock ;
13
15
const [ id ] = React . useState ( ( ) => {
14
16
uuid += 1 ;
Original file line number Diff line number Diff line change @@ -126,6 +126,32 @@ describe('Portal', () => {
126
126
overflowY : 'hidden' ,
127
127
} ) ;
128
128
} ) ;
129
+
130
+ it ( 'not lock screen when getContainer is not body' , ( ) => {
131
+ const div = document . createElement ( 'div' ) ;
132
+ document . body . appendChild ( div ) ;
133
+ render (
134
+ < Portal open autoLock getContainer = { ( ) => div } >
135
+ Bamboo
136
+ </ Portal > ,
137
+ ) ;
138
+
139
+ expect ( document . body ) . not . toHaveStyle ( {
140
+ overflowY : 'hidden' ,
141
+ } ) ;
142
+ } ) ;
143
+
144
+ it ( 'lock when getContainer give document.body' , ( ) => {
145
+ render (
146
+ < Portal open autoLock getContainer = { ( ) => document . body } >
147
+ Bamboo
148
+ </ Portal > ,
149
+ ) ;
150
+
151
+ expect ( document . body ) . toHaveStyle ( {
152
+ overflowY : 'hidden' ,
153
+ } ) ;
154
+ } ) ;
129
155
} ) ;
130
156
131
157
it ( 'autoDestroy' , ( ) => {
You can’t perform that action at this time.
0 commit comments