File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -22,20 +22,23 @@ const cssText = `
22
22
` ;
23
23
24
24
export default ( ) => {
25
+ const defaultRef = React . useRef < HTMLDivElement > ( ) ;
25
26
const webkitRef = React . useRef < HTMLDivElement > ( ) ;
26
27
const scrollRef = React . useRef < HTMLDivElement > ( ) ;
27
28
const [ sizeData , setSizeData ] = React . useState ( '' ) ;
28
29
29
30
React . useEffect ( ( ) => {
30
31
const originSize = getScrollBarSize ( ) ;
32
+ const defaultSize = getTargetScrollBarSize ( defaultRef . current ) ;
31
33
const webkitSize = getTargetScrollBarSize ( webkitRef . current ) ;
32
34
const scrollSize = getTargetScrollBarSize ( scrollRef . current ) ;
33
35
34
36
setSizeData (
35
37
[
36
38
`Origin: ${ originSize } ` ,
39
+ `Default: ${ defaultSize . width } /${ defaultSize . height } ` ,
37
40
`Webkit: ${ webkitSize . width } /${ webkitSize . height } ` ,
38
- `Webkit : ${ scrollSize . width } /${ scrollSize . height } ` ,
41
+ `Scroll : ${ scrollSize . width } /${ scrollSize . height } ` ,
39
42
] . join ( ', ' ) ,
40
43
) ;
41
44
} , [ ] ) ;
@@ -55,6 +58,7 @@ export default () => {
55
58
overflow : 'scroll' ,
56
59
background : 'yellow' ,
57
60
} }
61
+ ref = { defaultRef }
58
62
>
59
63
Origin
60
64
</ div >
Original file line number Diff line number Diff line change @@ -36,25 +36,31 @@ function measureScrollbarSize(ele?: HTMLElement): ScrollBarSize {
36
36
37
37
// Set Webkit style
38
38
const webkitScrollbarStyle = getComputedStyle ( ele , '::-webkit-scrollbar' ) ;
39
+ const width = parseInt ( webkitScrollbarStyle . width , 10 ) ;
40
+ const height = parseInt ( webkitScrollbarStyle . height , 10 ) ;
39
41
40
42
// Try wrap to handle CSP case
41
43
try {
44
+ const widthStyle = width ? `width: ${ webkitScrollbarStyle . width } ;` : '' ;
45
+ const heightStyle = height
46
+ ? `height: ${ webkitScrollbarStyle . height } ;`
47
+ : '' ;
48
+
42
49
updateCSS (
43
50
`
44
- #${ randomId } ::-webkit-scrollbar {
45
- width: ${ webkitScrollbarStyle . width } ;
46
- height: ${ webkitScrollbarStyle . height } ;
47
- }
48
- ` ,
51
+ #${ randomId } ::-webkit-scrollbar {
52
+ ${ widthStyle }
53
+ ${ heightStyle }
54
+ }` ,
49
55
randomId ,
50
56
) ;
51
57
} catch ( e ) {
52
58
// Can't wrap, just log error
53
59
console . error ( e ) ;
54
60
55
61
// Get from style directly
56
- fallbackWidth = parseInt ( webkitScrollbarStyle . width , 10 ) ;
57
- fallbackHeight = parseInt ( webkitScrollbarStyle . height , 10 ) ;
62
+ fallbackWidth = width ;
63
+ fallbackHeight = height ;
58
64
}
59
65
}
60
66
You can’t perform that action at this time.
0 commit comments