Skip to content

Commit a5bee49

Browse files
Fix scrollbar thumb crashing in React@next (v19) (#718)
Also fixes a scrollbar UI bug where the scrollbar thumb appears to always be in an active state even after finishing scrolling.
1 parent 134b18b commit a5bee49

File tree

3 files changed

+17
-66
lines changed

3 files changed

+17
-66
lines changed

Diff for: src/css/layout/ScrollbarLayout.css

+14-20
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,18 @@
2727
.ScrollbarLayout/mainHorizontal {
2828
height: var(--scrollbar-size);
2929
left: 0;
30-
transition-property: background-color height;
31-
}
32-
33-
/* Touching the scroll-track directly makes the scroll-track bolder */
34-
.ScrollbarLayout/mainHorizontal.public/Scrollbar/mainActive,
35-
.ScrollbarLayout/mainHorizontal:hover {
36-
height: var(--scrollbar-size-large);
3730
}
3831

3932
.ScrollbarLayout/face {
4033
left: 0;
4134
overflow: hidden;
4235
position: absolute;
4336
z-index: 1;
44-
transition-duration: 250ms;
45-
transition-timing-function: ease;
46-
transition-property: width;
37+
38+
/* keep the thumb aligned to the center */
39+
display: flex;
40+
justify-content: center;
41+
align-items: center;
4742
}
4843

4944
/**
@@ -57,7 +52,9 @@
5752
content: '';
5853
display: block;
5954
position: absolute;
60-
transition: background-color 250ms ease;
55+
transition-duration: 250ms;
56+
transition-timing-function: ease;
57+
transition-property: background-color, height, width;
6158
}
6259

6360
.ScrollbarLayout/faceHorizontal {
@@ -67,10 +64,8 @@
6764
}
6865

6966
.ScrollbarLayout/faceHorizontal:after {
70-
bottom: var(--scrollbar-face-margin);
71-
left: 0;
72-
top: var(--scrollbar-face-margin);
7367
width: 100%;
68+
height: calc(100% - var(--scrollbar-face-margin) * 2);
7469
}
7570

7671
.fixedDataTable_isRTL .ScrollbarLayout/faceHorizontal,
@@ -79,9 +74,10 @@
7974
left: auto;
8075
}
8176

77+
/* expand horizontal scrollbar face when active */
8278
.ScrollbarLayout/faceHorizontal.public/Scrollbar/faceActive:after,
8379
.ScrollbarLayout/main:hover .ScrollbarLayout/faceHorizontal:after {
84-
bottom: calc(var(--scrollbar-face-margin)/2);
80+
height: calc(100% - var(--scrollbar-face-margin));
8581
}
8682

8783
.ScrollbarLayout/faceVertical {
@@ -92,13 +88,11 @@
9288

9389
.ScrollbarLayout/faceVertical:after {
9490
height: 100%;
95-
left: var(--scrollbar-face-margin);
96-
right: var(--scrollbar-face-margin);
97-
top: 0;
91+
width: calc(100% - var(--scrollbar-face-margin) * 2);
9892
}
9993

94+
/* expand veritcal scrollbar face when active */
10095
.ScrollbarLayout/main:hover .ScrollbarLayout/faceVertical:after,
10196
.ScrollbarLayout/faceVertical.public/Scrollbar/faceActive:after {
102-
left: calc(var(--scrollbar-face-margin)/2);
103-
right: calc(var(--scrollbar-face-margin)/2);
97+
width: calc(100% - var(--scrollbar-face-margin));
10498
}

Diff for: src/plugins/Scrollbar.js

+3-45
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ const FACE_MARGIN_2 = FACE_MARGIN * 2;
3333
const FACE_SIZE_MIN = 30;
3434
const KEYBOARD_SCROLL_AMOUNT = 40;
3535

36-
let _lastScrolledScrollbar = null;
37-
3836
class Scrollbar extends React.PureComponent {
3937
static propTypes = {
4038
contentSize: PropTypes.number.isRequired,
@@ -110,7 +108,7 @@ class Scrollbar extends React.PureComponent {
110108
let faceStyle;
111109
const isHorizontal = this.state.isHorizontal;
112110
const isVertical = !isHorizontal;
113-
const isActive = this.state.focused || this.state.isDragging;
111+
const isActive = this.state.isDragging;
114112
const faceSize = this.state.faceSize;
115113
const isOpaque = this.props.isOpaque;
116114
const verticalTop = this.props.verticalTop || 0;
@@ -182,8 +180,6 @@ class Scrollbar extends React.PureComponent {
182180

183181
return (
184182
<div
185-
onFocus={this._onFocus}
186-
onBlur={this._onBlur}
187183
onKeyDown={this._onKeyDown}
188184
onMouseDown={this._onMouseDown}
189185
onTouchCancel={this._onTouchCancel}
@@ -244,9 +240,6 @@ class Scrollbar extends React.PureComponent {
244240
this._mouseMoveTracker.releaseMouseMoves();
245241
this._mouseMoveTracker = null;
246242
}
247-
if (_lastScrolledScrollbar === this) {
248-
_lastScrolledScrollbar = null;
249-
}
250243
}
251244

252245
scrollBy = (/*number*/ delta) => {
@@ -313,15 +306,10 @@ class Scrollbar extends React.PureComponent {
313306
position = maxPosition;
314307
}
315308

316-
const isDragging = this._mouseMoveTracker
317-
? this._mouseMoveTracker.isDragging()
318-
: false;
319-
320309
// This function should only return flat values that can be compared quiclky
321310
// by `ReactComponentWithPureRenderMixin`.
322311
const state = {
323312
faceSize,
324-
isDragging,
325313
isHorizontal,
326314
position,
327315
scale,
@@ -358,6 +346,8 @@ class Scrollbar extends React.PureComponent {
358346
};
359347

360348
_onMouseDown = (/*object*/ event) => {
349+
this.setState({ isDragging: true });
350+
361351
/** @type {object} */
362352
let nextState;
363353

@@ -387,7 +377,6 @@ class Scrollbar extends React.PureComponent {
387377
nextState = {};
388378
}
389379

390-
nextState.focused = true;
391380
this._setNextState(nextState);
392381

393382
this._mouseMoveTracker.captureMouseMoves(event);
@@ -535,32 +524,6 @@ class Scrollbar extends React.PureComponent {
535524
);
536525
};
537526

538-
_onFocus = () => {
539-
this.setState({
540-
focused: true,
541-
});
542-
};
543-
544-
_onBlur = () => {
545-
this.setState({
546-
focused: false,
547-
});
548-
};
549-
550-
_blur = () => {
551-
const el = ReactDOM.findDOMNode(this);
552-
if (!el) {
553-
return;
554-
}
555-
556-
try {
557-
this._onBlur();
558-
el.blur();
559-
} catch (oops) {
560-
// pass
561-
}
562-
};
563-
564527
getTouchX = (/*object*/ e) => {
565528
return Math.round(
566529
e.targetTouches[0].clientX - e.target.getBoundingClientRect().x
@@ -593,11 +556,6 @@ class Scrollbar extends React.PureComponent {
593556
}
594557
return;
595558
}
596-
597-
if (willScroll && _lastScrolledScrollbar !== this) {
598-
_lastScrolledScrollbar && _lastScrolledScrollbar._blur();
599-
_lastScrolledScrollbar = this;
600-
}
601559
};
602560

603561
_didScroll = () => {

Diff for: src/stubs/cssVar.js

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const CSS_VARS = {
1919
'--scrollbar-face-margin': '4px',
2020
'--scrollbar-face-radius': '6px',
2121
'--scrollbar-size': '15px',
22-
'--scrollbar-size-large': '17px',
2322
'--scrollbar-track-color': '#fff',
2423
'--border-color': '#d3d3d3',
2524
'--fbui-white': '#fff',

0 commit comments

Comments
 (0)