Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix mouseup trigger change #900

Merged
merged 2 commits into from
Dec 21, 2018
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: 2 additions & 3 deletions src/js/bootstrap-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -1749,8 +1749,7 @@ const windowIsDefined = (typeof window === "object");
}
var val = this._calculateValue(true);

this._layout();
this._setDataVal(val);
this.setValue(val, false, true);
this._trigger('slideStop', val);

// No longer need 'dragged' after mouse up
Expand All @@ -1773,7 +1772,7 @@ const windowIsDefined = (typeof window === "object");
if (snapToClosestTick) {
val[0] = this._snapToClosestTick(val[0]);
val[1] = this._snapToClosestTick(val[1]);
}
}
} else {
val = this._toValue(this._state.percentage[0]);
val = this._applyPrecision(val);
Expand Down
34 changes: 33 additions & 1 deletion test/specs/DraggingHandlesSpec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
describe("Dragging handles tests", function() {
var testSlider;
var mouseEventArguments;
var tickOffsets;
var tickOffsets;

// Create mouse events
function mouseEvent(type, offset) {
var ev = document.createEvent("MouseEvents");
mouseEventArguments[0] = type;
mouseEventArguments[7] = offset;
ev.initMouseEvent.apply(ev, mouseEventArguments);
return ev;
}

beforeEach(function() {
// Create slider
Expand Down Expand Up @@ -210,7 +219,30 @@ describe("Dragging handles tests", function() {
// End with mouse up
testSlider.mouseup(mouseRight);
expect(testSlider.getValue()).toEqual([2, 5]);
});

it("Should trigger change on mouseup", function() {
var ups = 0;
var changes = 0;

testSlider.on('slideStop', function(){
expect(changes).toBe(1);
ups++;
});

testSlider.mousedown(mouseEvent('mousedown', tickOffsets[1]));
expect(testSlider.getValue()).toEqual([1, 5]);
expect(ups).toBe(0);

testSlider.on('change', function(){
expect(ups).toBe(0);
changes++;
});

testSlider.mouseup(mouseEvent('mouseup', tickOffsets[2]));
expect(testSlider.getValue()).toEqual([2, 5]);
expect(changes).toBe(1);
expect(ups).toBe(1);
});

describe("Test 'mousemove' and 'mouseup' produces correct results", function() {
Expand Down