Skip to content

Commit 49c3150

Browse files
zangchuqiange1emeb0t
authored andcommitted
fix: autoComplete item panel, drag scrollbar error
1 parent ffdfeab commit 49c3150

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/scrollbar/Bar.jsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ import { BAR_MAP, renderThumbStyle} from './util';
44
import {on, off} from '../../libs/utils/dom';
55

66
export class Bar extends Component {
7-
87
constructor(props) {
98
super(props);
9+
10+
this.clickTrackHandler = this.clickTrackHandler.bind(this);
11+
this.clickThumbHandler = this.clickThumbHandler.bind(this);
12+
this.mouseMoveDocumentHandler = this.mouseMoveDocumentHandler.bind(this);
13+
this.mouseUpDocumentHandler = this.mouseUpDocumentHandler.bind(this);
1014
}
1115

1216
get bar() {
@@ -24,14 +28,14 @@ export class Bar extends Component {
2428

2529
clickTrackHandler(e) {
2630
const offset = Math.abs(e.target.getBoundingClientRect()[this.bar.direction] - e[this.bar.client]);
27-
const thumbHalf = (this.refs.thumb[this.bar.offset] / 2);
28-
const thumbPositionPercentage = ((offset - thumbHalf) * 100 / this.root[this.bar.offset]);
31+
const thumbHalf = (this.thumbRef[this.bar.offset] / 2);
32+
const thumbPositionPercentage = ((offset - thumbHalf) * 100 / this.rootRef[this.bar.offset]);
2933

3034
this.wrap[this.bar.scroll] = (thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100);
3135
}
3236

3337
startDrag(e) {
34-
e.stopImmediatePropagation();
38+
e.nativeEvent.stopImmediatePropagation;
3539
this.cursorDown = true;
3640

3741
on(document, 'mousemove', this.mouseMoveDocumentHandler);
@@ -45,9 +49,9 @@ export class Bar extends Component {
4549

4650
if (!prevPage) return;
4751

48-
const offset = (e[this.bar.client] - this.root.getBoundingClientRect()[this.bar.direction]);
49-
const thumbClickPosition = (this.refs.thumb[this.bar.offset] - prevPage);
50-
const thumbPositionPercentage = ((offset - thumbClickPosition) * 100 / this.root[this.bar.offset]);
52+
const offset = (e[this.bar.client] - this.rootRef.getBoundingClientRect()[this.bar.direction]);
53+
const thumbClickPosition = (this.thumbRef[this.bar.offset] - prevPage);
54+
const thumbPositionPercentage = ((offset - thumbClickPosition) * 100 / this.rootRef[this.bar.offset]);
5155

5256
this.wrap[this.bar.scroll] = (thumbPositionPercentage * this.wrap[this.bar.scrollSize] / 100);
5357
}
@@ -64,13 +68,13 @@ export class Bar extends Component {
6468

6569
return (
6670
<div
67-
ref="root"
71+
ref={root => this.rootRef = root}
6872
className={this.classNames('el-scrollbar__bar', `is-${this.bar.key}`)}
69-
onMouseDown={ this.clickTrackHandler.bind(this) } >
73+
onMouseDown={ this.clickTrackHandler } >
7074
<div
71-
ref="thumb"
75+
ref={thumb => this.thumbRef = thumb}
7276
className="el-scrollbar__thumb"
73-
onMouseDown={ this.clickThumbHandler.bind(this) }
77+
onMouseDown={ this.clickThumbHandler }
7478
style={ renderThumbStyle({ size, move, bar: this.bar }) }>
7579
</div>
7680
</div>
@@ -83,5 +87,4 @@ Bar.propTypes = {
8387
size: PropTypes.string,
8488
move: PropTypes.number,
8589
getParentWrap: PropTypes.func.isRequired
86-
8790
}

0 commit comments

Comments
 (0)