Skip to content

Commit

Permalink
fix(Slider): dont call refine() when it's disabled
Browse files Browse the repository at this point in the history
see: #2169
  • Loading branch information
iam4x committed Jun 1, 2017
1 parent b78e358 commit f1eabc9
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/components/Slider/Slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ class Slider extends Component {
]),
}

get isDisabled() {
return this.props.min === this.props.max;
}

handleChange = ({values}) => {
const {refine} = this.props;
refine(values);
// when Slider is disabled, we alter `min, max` values
// in order to render a "disabled state" Slider. Since we alter
// theses values, Rheostat trigger a "change" event which trigger a new

This comment has been minimized.

Copy link
@Haroenv

Haroenv Jun 1, 2017

Contributor

nice change; small nit: triggers

// search to Algolia with wrong values.
if (!this.isDisabled) {
const {refine} = this.props;
refine(values);
}
}

// creates an array number where to display a pit point on the slider
Expand Down Expand Up @@ -79,8 +89,7 @@ class Slider extends Component {
render() {
const {tooltips, step, pips, values} = this.props;

const isDisabled = this.props.min === this.props.max;
const {min, max} = isDisabled
const {min, max} = this.isDisabled
? {min: this.props.min, max: this.props.max + 0.001}
: this.props;

Expand All @@ -90,7 +99,7 @@ class Slider extends Component {
: pips;

return (
<div className={ isDisabled ? 'ais-range-slider--disabled' : '' }>
<div className={ this.isDisabled ? 'ais-range-slider--disabled' : '' }>
<Rheostat
handle={ this.createHandleComponent(tooltips) }
onChange={ this.handleChange }
Expand All @@ -100,8 +109,8 @@ class Slider extends Component {
pitPoints={ pitPoints }
snap={ true }
snapPoints={ snapPoints }
values={ isDisabled ? [min, max] : values }
disabled={ isDisabled }
values={ this.isDisabled ? [min, max] : values }
disabled={ this.isDisabled }
/>
</div>
);
Expand Down

0 comments on commit f1eabc9

Please sign in to comment.