Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface ListProps<T> extends Omit<React.HTMLAttributes<any>, 'children'
verticalScrollBar?: React.CSSProperties;
verticalScrollBarThumb?: React.CSSProperties;
};

showScrollBar?: boolean | 'optional';
onScroll?: React.UIEventHandler<HTMLElement>;

/**
Expand Down Expand Up @@ -112,6 +112,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
innerProps,
extraRender,
styles,
showScrollBar = 'optional',
...restProps
} = props;

Expand Down Expand Up @@ -640,6 +641,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
containerSize={size.height}
style={styles?.verticalScrollBar}
thumbStyle={styles?.verticalScrollBarThumb}
showScrollBar={showScrollBar}
/>
)}

Expand All @@ -658,6 +660,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
horizontal
style={styles?.horizontalScrollBar}
thumbStyle={styles?.horizontalScrollBarThumb}
showScrollBar={showScrollBar}
/>
)}
</div>
Expand Down
6 changes: 4 additions & 2 deletions src/ScrollBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ScrollBarProps {
thumbStyle?: React.CSSProperties;
spinSize: number;
containerSize: number;
showScrollBar?: boolean | 'optional';
}

export interface ScrollBarRef {
Expand All @@ -38,6 +39,7 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
containerSize,
style,
thumbStyle: propsThumbStyle,
showScrollBar,
} = props;

const [dragging, setDragging] = React.useState(false);
Expand All @@ -51,13 +53,13 @@ const ScrollBar = React.forwardRef<ScrollBarRef, ScrollBarProps>((props, ref) =>
const thumbRef = React.useRef<HTMLDivElement>();

// ======================= Visible ========================
const [visible, setVisible] = React.useState(false);
const [visible, setVisible] = React.useState(showScrollBar);
const visibleTimeoutRef = React.useRef<ReturnType<typeof setTimeout>>();

const delayHidden = () => {
if (showScrollBar === true || showScrollBar === false) return;
clearTimeout(visibleTimeoutRef.current);
setVisible(true);

visibleTimeoutRef.current = setTimeout(() => {
setVisible(false);
}, 3000);
Expand Down
19 changes: 19 additions & 0 deletions tests/scroll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,25 @@ describe('List.Scroll', () => {
expect(wrapper.find('ul').instance().scrollTop > 10).toBeTruthy();
});

it('should show scrollbar when element has showScrollBar prop set to true', () => {
jest.useFakeTimers();
const listRef = React.createRef();
const { container } = genList(
{
itemHeight: 20,
height: 100,
data: genData(100),
ref: listRef,
showScrollBar: true,
},
render,
);
act(() => {
jest.runAllTimers();
});
const scrollbarElement = container.querySelector('.rc-virtual-list-scrollbar-visible');
expect(scrollbarElement).not.toBeNull();
});
describe('not show scrollbar when disabled virtual', () => {
[
{ name: '!virtual', props: { virtual: false } },
Expand Down
Loading