File tree Expand file tree Collapse file tree 2 files changed +45
-5
lines changed
Expand file tree Collapse file tree 2 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 11import * as React from 'react' ;
22import { updateCSS , removeCSS } from 'rc-util/lib/Dom/dynamicCSS' ;
33import useLayoutEffect from 'rc-util/lib/hooks/useLayoutEffect' ;
4- import getScrollBarSize from 'rc-util/lib/getScrollBarSize' ;
4+ import { getTargetScrollBarSize } from 'rc-util/lib/getScrollBarSize' ;
55import { isBodyOverflowing } from './util' ;
66
77const UNIQUE_ID = `rc-util-locker-${ Date . now ( ) } ` ;
88
99let uuid = 0 ;
1010
11- export default function useScrollLocker (
12- lock ?: boolean ,
13- ) {
11+ export default function useScrollLocker ( lock ?: boolean ) {
1412 const mergedLock = ! ! lock ;
1513 const [ id ] = React . useState ( ( ) => {
1614 uuid += 1 ;
@@ -19,7 +17,7 @@ export default function useScrollLocker(
1917
2018 useLayoutEffect ( ( ) => {
2119 if ( mergedLock ) {
22- const scrollbarSize = getScrollBarSize ( ) ;
20+ const scrollbarSize = getTargetScrollBarSize ( document . body ) . width ;
2321 const isOverflow = isBodyOverflowing ( ) ;
2422
2523 updateCSS (
Original file line number Diff line number Diff line change 1+ import React from 'react' ;
2+ import { render } from '@testing-library/react' ;
3+ import Portal from '../src' ;
4+ import { updateCSS } from 'rc-util/lib/Dom/dynamicCSS' ;
5+
6+ jest . mock ( '../src/util' , ( ) => {
7+ const origin = jest . requireActual ( '../src/util' ) ;
8+ return {
9+ ...origin ,
10+ isBodyOverflowing : ( ) => true ,
11+ } ;
12+ } ) ;
13+
14+ // Revert `useLayoutEffect` back to real one since we should keep order for test
15+ jest . mock ( 'rc-util/lib/hooks/useLayoutEffect' , ( ) => {
16+ const origin = jest . requireActual ( 'react' ) ;
17+ return origin . useLayoutEffect ;
18+ } ) ;
19+
20+ // Revert `useLayoutEffect` back to real one since we should keep order for test
21+ jest . mock ( 'rc-util/lib/getScrollBarSize' , ( ) => {
22+ const origin = jest . requireActual ( 'rc-util/lib/getScrollBarSize' ) ;
23+ return {
24+ ...origin ,
25+
26+ getTargetScrollBarSize : ( ) => ( { width : 93 , height : 1128 } ) ,
27+ } ;
28+ } ) ;
29+
30+ describe ( '::-webkit-scrollbar' , ( ) => {
31+ it ( 'support ::-webkit-scrollbar' , ( ) => {
32+ render (
33+ < Portal open autoLock >
34+ < p />
35+ </ Portal > ,
36+ ) ;
37+
38+ expect ( document . body ) . toHaveStyle ( {
39+ width : 'calc(100% - 93px)' ,
40+ } ) ;
41+ } ) ;
42+ } ) ;
You can’t perform that action at this time.
0 commit comments