Skip to content

Commit 400d370

Browse files
authored
feat: Add one more className (#142)
* feat: Add one more className * chore: clean up
1 parent eeb7bdb commit 400d370

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

examples/switch.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
/* eslint-disable jsx-a11y/label-has-associated-control, jsx-a11y/label-has-for */
21
import * as React from 'react';
3-
import List, { ListRef } from '../src/List';
2+
import type { ListRef } from '../src/List';
3+
import List from '../src/List';
44

55
interface Item {
66
id: number;
@@ -37,6 +37,7 @@ function getData(count: number) {
3737
const Demo = () => {
3838
const [height, setHeight] = React.useState(200);
3939
const [data, setData] = React.useState(getData(20));
40+
const [fullHeight, setFullHeight] = React.useState(true);
4041
const listRef = React.useRef<ListRef>();
4142

4243
return (
@@ -98,13 +99,23 @@ const Demo = () => {
9899
200
99100
</label>
100101
</span>
102+
<span>
103+
<button
104+
onClick={() => {
105+
setFullHeight(!fullHeight);
106+
}}
107+
>
108+
Full Height: {String(fullHeight)}
109+
</button>
110+
</span>
101111

102112
<List
103113
ref={listRef}
104114
data={data}
105115
height={height}
106116
itemHeight={10}
107117
itemKey="id"
118+
fullHeight={fullHeight}
108119
style={{
109120
border: '1px solid red',
110121
boxSizing: 'border-box',

src/ScrollBar.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar
7171
e.preventDefault();
7272
};
7373

74-
onContainerMouseDown: React.MouseEventHandler = e => {
74+
onContainerMouseDown: React.MouseEventHandler = (e) => {
7575
e.stopPropagation();
7676
e.preventDefault();
7777
};
@@ -173,38 +173,35 @@ export default class ScrollBar extends React.Component<ScrollBarProps, ScrollBar
173173
return ptg * enableHeightRange;
174174
};
175175

176-
// Not show scrollbar when height is large thane scrollHeight
177-
getVisible = (): boolean => {
178-
const { visible } = this.state;
176+
// Not show scrollbar when height is large than scrollHeight
177+
showScroll = (): boolean => {
179178
const { height, scrollHeight } = this.props;
180-
181-
if (height >= scrollHeight) {
182-
return false;
183-
}
184-
185-
return visible;
179+
return scrollHeight > height;
186180
};
187181

188182
// ====================== Render =======================
189183
render() {
190-
const { dragging } = this.state;
184+
const { dragging, visible } = this.state;
191185
const { prefixCls } = this.props;
192186
const spinHeight = this.getSpinHeight();
193187
const top = this.getTop();
194188

195-
const visible = this.getVisible();
189+
const canScroll = this.showScroll();
190+
const mergedVisible = canScroll && visible;
196191

197192
return (
198193
<div
199194
ref={this.scrollbarRef}
200-
className={`${prefixCls}-scrollbar`}
195+
className={classNames(`${prefixCls}-scrollbar`, {
196+
[`${prefixCls}-scrollbar-show`]: canScroll,
197+
})}
201198
style={{
202199
width: 8,
203200
top: 0,
204201
bottom: 0,
205202
right: 0,
206203
position: 'absolute',
207-
display: visible ? null : 'none',
204+
display: mergedVisible ? null : 'none',
208205
}}
209206
onMouseDown={this.onContainerMouseDown}
210207
onMouseMove={this.delayHidden}

0 commit comments

Comments
 (0)