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

Add disabled prop to render without interaction #123

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
36 changes: 23 additions & 13 deletions src/Rangeslider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Slider extends Component {
orientation: PropTypes.string,
tooltip: PropTypes.bool,
reverse: PropTypes.bool,
disabled: PropTypes.bool,
labels: PropTypes.object,
handleLabel: PropTypes.string,
format: PropTypes.func,
Expand All @@ -52,7 +53,8 @@ class Slider extends Component {
tooltip: true,
reverse: false,
labels: {},
handleLabel: ''
handleLabel: '',
disabled: false
};

constructor (props, context) {
Expand Down Expand Up @@ -303,6 +305,11 @@ class Slider extends Component {
let labelItems = []
let labelKeys = Object.keys(labels)

const handleDrag = (this.props.disabled ? undefined : this.handleDrag)
const handleStart = (this.props.disabled ? undefined : this.handleStart)
const handleEnd = (this.props.disabled ? undefined : this.handleEnd)
const handleKeyDown = (this.props.disabled ? undefined : this.handleKeyDown)

if (labelKeys.length > 0) {
labelKeys = labelKeys.sort((a, b) => (reverse ? a - b : b - a))

Expand All @@ -316,9 +323,9 @@ class Slider extends Component {
key={key}
className={cx('rangeslider__label-item')}
data-value={key}
onMouseDown={this.handleDrag}
onTouchStart={this.handleStart}
onTouchEnd={this.handleEnd}
onMouseDown={handleDrag}
onTouchStart={handleStart}
onTouchEnd={handleEnd}
style={labelStyle}
>
{this.props.labels[key]}
Expand All @@ -335,13 +342,16 @@ class Slider extends Component {
className={cx(
'rangeslider',
`rangeslider-${orientation}`,
{ 'rangeslider-reverse': reverse },
{
'rangeslider-reverse': reverse,
'rangeslider-disabled': this.props.disabled
},
className
)}
onMouseDown={this.handleDrag}
onMouseUp={this.handleEnd}
onTouchStart={this.handleStart}
onTouchEnd={this.handleEnd}
onMouseDown={handleDrag}
onMouseUp={handleEnd}
onTouchStart={handleStart}
onTouchEnd={handleEnd}
aria-valuemin={min}
aria-valuemax={max}
aria-valuenow={value}
Expand All @@ -353,10 +363,10 @@ class Slider extends Component {
this.handle = sh
}}
className='rangeslider__handle'
onMouseDown={this.handleStart}
onTouchMove={this.handleDrag}
onTouchEnd={this.handleEnd}
onKeyDown={this.handleKeyDown}
onMouseDown={handleStart}
onTouchMove={handleDrag}
onTouchEnd={handleEnd}
onKeyDown={handleKeyDown}
style={handleStyle}
tabIndex={0}
>
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/Rangeslider.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ describe('Rangeslider specs', () => {
expect(slider.prop('reverse')).toEqual(false)
expect(slider.prop('handleLabel')).toEqual('')
expect(slider.prop('labels')).toEqual({})
expect(slider.prop('disabled')).toEqual(false)
})

it('should render basic slider with defaults', () => {
Expand Down