File tree Expand file tree Collapse file tree 3 files changed +37
-1
lines changed
Expand file tree Collapse file tree 3 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import useLayoutEffect, {
44 useLayoutUpdateEffect ,
55} from 'rc-util/lib/hooks/useLayoutEffect' ;
66import getScrollBarSize from 'rc-util/lib/getScrollBarSize' ;
7+ import { isBodyOverflowing } from './util' ;
78
89let lockCount = 0 ;
910let locked = false ;
@@ -18,11 +19,13 @@ function syncLocker() {
1819
1920 if ( locked ) {
2021 const scrollbarSize = getScrollBarSize ( ) ;
22+ const isOverflow = isBodyOverflowing ( ) ;
23+
2124 updateCSS (
2225 `
2326html body {
2427 overflow-y: hidden;
25- width: calc(100% - ${ scrollbarSize } px);
28+ ${ isOverflow ? ` width: calc(100% - ${ scrollbarSize } px);` : '' }
2629}` ,
2730 UNIQUE_ID ,
2831 ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Test usage export. Do not use in your production
3+ */
4+ export function isBodyOverflowing ( ) {
5+ return (
6+ document . body . scrollHeight >
7+ ( window . innerHeight || document . documentElement . clientHeight ) &&
8+ window . innerWidth > document . body . offsetWidth
9+ ) ;
10+ }
Original file line number Diff line number Diff line change @@ -2,7 +2,21 @@ import React from 'react';
22import { render } from '@testing-library/react' ;
33import Portal from '../src' ;
44
5+ global . isOverflow = true ;
6+
7+ jest . mock ( '../src/util' , ( ) => {
8+ const origin = jest . requireActual ( '../src/util' ) ;
9+ return {
10+ ...origin ,
11+ isBodyOverflowing : ( ) => global . isOverflow ,
12+ } ;
13+ } ) ;
14+
515describe ( 'Portal' , ( ) => {
16+ beforeEach ( ( ) => {
17+ global . isOverflow = true ;
18+ } ) ;
19+
620 it ( 'Order' , ( ) => {
721 render (
822 < Portal open debug = "root" >
@@ -103,5 +117,14 @@ describe('Portal', () => {
103117 test ( 'StrictMode' , {
104118 wrapper : React . StrictMode ,
105119 } ) ;
120+
121+ it ( 'window not scrollable' , ( ) => {
122+ global . isOverflow = false ;
123+ render ( < Portal open /> ) ;
124+
125+ expect ( document . body ) . not . toHaveStyle ( {
126+ overflowY : 'hidden' ,
127+ } ) ;
128+ } ) ;
106129 } ) ;
107130} ) ;
You can’t perform that action at this time.
0 commit comments