Skip to content

Commit

Permalink
feat: add "dragging" class when scrollbar is dragged (fix #258 #268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Grsmto committed Feb 18, 2019
1 parent 54c0e4a commit c42e7e4
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
7 changes: 7 additions & 0 deletions packages/simplebar/demo/browser/css/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ p {
padding: 10px;
min-width: 230px;
}
.demo1 p.odd:hover {
background: #666;
}
.demo1 p.odd {
background: #f0f0f0;
}
Expand Down Expand Up @@ -149,6 +152,10 @@ p {
height: 200px;
}

.demo-y-axis.simplebar-dragging .simplebar-scrollbar:before {
background-color: red;
}

.demo-both-axis .box,
.demo-y-axis .box {
width: 600px;
Expand Down
4 changes: 4 additions & 0 deletions packages/simplebar/src/simplebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
pointer-events: none;
}

[data-simplebar].simplebar-dragging .simplebar-track {
pointer-events: all;
}

.simplebar-scrollbar {
position: absolute;
right: 2px;
Expand Down
7 changes: 6 additions & 1 deletion packages/simplebar/src/simplebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export default class SimpleBar {
visible: 'simplebar-visible',
horizontal: 'simplebar-horizontal',
vertical: 'simplebar-vertical',
hover: 'simplebar-hover'
hover: 'simplebar-hover',
dragging: 'simplebar-dragging',
},
scrollbarMinSize: 25,
scrollbarMaxSize: 0,
Expand Down Expand Up @@ -746,6 +747,8 @@ export default class SimpleBar {
scrollbar.getBoundingClientRect()[this.axis[axis].offsetAttr];
this.draggedAxis = axis;

this.el.classList.add(this.classNames.dragging);

document.addEventListener('mousemove', this.drag);
document.addEventListener('mouseup', this.onEndDrag);
}
Expand Down Expand Up @@ -802,6 +805,8 @@ export default class SimpleBar {
e.preventDefault();
e.stopPropagation();

this.el.classList.remove(this.classNames.dragging);

document.removeEventListener('mousemove', this.drag);
document.removeEventListener('mouseup', this.onEndDrag);
};
Expand Down
13 changes: 13 additions & 0 deletions packages/simplebar/test/simplebar.test.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ describe('Load', () => {
expect(isRtl).toBeTruthy();
expect(transformStyle).toEqual(`translate3d(${ elBoundingBox.width - scrollbarElBoundingBox.width}px, 0px, 0px)`);
});

it('should add class "dragging" when dragging', async () => {
const el = await expect(page).toMatchElement('#demo2');

await page.click('#demo2 .simplebar-track.simplebar-vertical .simplebar-scrollbar');
await page.mouse.down();

const isDragging = await page.evaluate(el => el.classList.contains('simplebar-dragging'), el);

expect(isDragging).toBeTruthy();
}, 999999);
});

// await jestPuppeteer.debug();

0 comments on commit c42e7e4

Please sign in to comment.