Skip to content

Commit 9456e3e

Browse files
authored
Merge pull request #244 from Codebrahma/slider
🐛 (slider)-bug fixes
2 parents eabe653 + 17aaedd commit 9456e3e

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

lib/slider/index.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,14 @@ class Slider extends React.Component {
131131
}
132132
};
133133

134-
startDrag = (_, left) => {
135-
const dragEventWithData = e => this.dragEvent(e, left);
136-
document.body.addEventListener('mouseup', () => this.stopDrag(dragEventWithData));
137-
document.body.addEventListener('mousemove', dragEventWithData);
134+
startDrag = (ev, left) => {
135+
ev.preventDefault();
136+
const { disabled } = this.props;
137+
if (!disabled) {
138+
const dragEventWithData = e => this.dragEvent(e, left);
139+
document.body.addEventListener('mouseup', () => this.stopDrag(dragEventWithData));
140+
document.body.addEventListener('mousemove', dragEventWithData);
141+
}
138142
};
139143

140144
stopDrag = (eventCallback) => {
@@ -167,16 +171,16 @@ class Slider extends React.Component {
167171
const leftButtonProps = {
168172
className: theme['slider-button'],
169173
'aria-label': 'slider-button-left',
170-
onMouseDown: !disabled ? (e) => {
174+
onMouseDown: (e) => {
171175
this.startDrag(e, true);
172-
} : undefined,
176+
},
173177
};
174178
const rightButtonProps = {
175179
className: theme['slider-button'],
176180
'aria-label': 'slider-button-right',
177-
onMouseDown: !disabled ? (e) => {
181+
onMouseDown: (e) => {
178182
this.startDrag(e, false);
179-
} : undefined,
183+
},
180184
};
181185
return (
182186
<div {...rootProps}>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React from 'react';
2+
import { mount } from 'enzyme';
3+
import { expect } from 'chai';
4+
import Slider from '..';
5+
6+
/* eslint-disable no-undef */
7+
describe('Slider Accessibility tests tests', () => {
8+
let wrappedComponent;
9+
10+
// beforeEach(() => {
11+
// });
12+
13+
afterEach(() => {
14+
wrappedComponent.unmount();
15+
});
16+
17+
it('Is disabled when disabled prop is passed', () => {
18+
wrappedComponent = mount(<Slider disabled />);
19+
expect(wrappedComponent.props().disabled).equals(true);
20+
});
21+
});

0 commit comments

Comments
 (0)