Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/Slider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,8 @@ class Rheostat extends React.Component {
document.attachEvent('onmouseup', this.endSlide);
}

if (this.props.onSliderDragStart) this.props.onSliderDragStart(ev);

killEvent(ev);
}

Expand All @@ -390,7 +392,7 @@ class Rheostat extends React.Component {
document.addEventListener('touchmove', this.handleTouchSlide, false);
document.addEventListener('touchend', this.endSlide, false);

if (this.props.onSliderDragStart) this.props.onSliderDragStart();
if (this.props.onSliderDragStart) this.props.onSliderDragStart(ev);

killEvent(ev);
}
Expand Down
20 changes: 20 additions & 0 deletions test/slider-test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,26 @@ describe('<Slider />', () => {
assert(slider.state('handlePos').length === 2, 'two handles exist');
});
});

it('fires onSliderDragStart when clicked or touched', () => {
const onSliderDragStart = sinon.spy();
const wrapper = mount(<Slider onSliderDragStart={onSliderDragStart} values={[50]} />);
const handle = wrapper.find('.rheostat-handle');
handle.simulate('mouseDown', { clientX: 0, clientY: 0 });
assert(onSliderDragStart.callCount === 1, 'onDragStart was called from mouseDown');
assert(onSliderDragStart.calledWithMatch({ clientX: 0, clientY: 0 }));
const touchProps = {
changedTouches: [
{
clientX: 0,
clientY: 0,
},
],
};
handle.simulate('touchStart', touchProps);
assert(onSliderDragStart.callCount === 2, 'onDragStart was called from touchStart');
assert(onSliderDragStart.calledWithMatch(touchProps));
});
});

describe('Slider API', () => {
Expand Down