Skip to content

Commit edfac3e

Browse files
linxianxizombieJ
andauthored
fix: modify scroll bar size (#252)
* fix: modify scroll bar size * test: modify test case --------- Co-authored-by: 二货机器人 <[email protected]>
1 parent 2d4aef8 commit edfac3e

File tree

4 files changed

+5
-9
lines changed

4 files changed

+5
-9
lines changed

src/List.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
576576
/>
577577
)}
578578

579-
{inVirtual && scrollWidth && (
579+
{inVirtual && scrollWidth > size.width && (
580580
<ScrollBar
581581
ref={horizontalScrollBarRef}
582582
prefixCls={prefixCls}

src/ScrollBar.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
7474
const enableScrollRange = scrollRange - containerSize || 0;
7575
const enableOffsetRange = containerSize - spinSize || 0;
7676

77-
// `scrollWidth` < `clientWidth` means no need to show scrollbar
78-
const canScroll = enableScrollRange > 0;
79-
8077
// ========================= Top ==========================
8178
const top = React.useMemo(() => {
8279
if (scrollOffset === 0 || enableScrollRange === 0) {
@@ -87,7 +84,7 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
8784
}, [scrollOffset, enableScrollRange, enableOffsetRange]);
8885

8986
// ====================== Container =======================
90-
const onContainerMouseDown: React.MouseEventHandler = (e) => {
87+
const onContainerMouseDown: React.MouseEventHandler = e => {
9188
e.stopPropagation();
9289
e.preventDefault();
9390
};
@@ -206,7 +203,7 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
206203

207204
const containerStyle: React.CSSProperties = {
208205
position: 'absolute',
209-
visibility: visible && canScroll ? null : 'hidden',
206+
visibility: visible ? null : 'hidden',
210207
};
211208

212209
const thumbStyle: React.CSSProperties = {

src/utils/scrollbarUtil.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
const MIN_SIZE = 20;
22

33
export function getSpinSize(containerSize = 0, scrollRange = 0) {
4-
let baseSize = (containerSize / scrollRange) * 100;
4+
let baseSize = (containerSize / scrollRange) * containerSize;
55
if (isNaN(baseSize)) {
66
baseSize = 0;
77
}
88
baseSize = Math.max(baseSize, MIN_SIZE);
9-
baseSize = Math.min(baseSize, containerSize / 2);
109
return Math.floor(baseSize);
1110
}

tests/scroll.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ describe('List.Scroll', () => {
470470
});
471471

472472
expect(container.querySelector('.rc-virtual-list-scrollbar-thumb')).toHaveStyle({
473-
height: `10px`,
473+
height: `20px`,
474474
});
475475
});
476476
});

0 commit comments

Comments
 (0)