Edit: put in entire code as requested. There are a few changes from the original.
I'm trying to use the foundation slider with react and ES6. When the slider moves, it's supposed to emit a moved.zf.slider event. React is supposed to be able to bind to custom events. My code:
//React and third party references
import React, { Component } from 'react';
import PropTypes from 'prop-types';
class SearchRangeFilter extends Component {
constructor(props) {
super(props);
this.handleSliderMove = this.handleSliderMove.bind(this);
}
componentDidMount(){
this.nv.addEventListener("moved.zf.slider", this.handleSliderMove);
}
componentWillUnmount(){
this.nv.removeEventListener('moved.zf.slider', this.handleSliderMove);
}
handleSliderMove(){
console.log("Nv Enter:");
}
render() {
return (
<div id="distance-selector-wrapper" className="flex-wrapper">
<div className="range-slider__wrapper">
<div ref={elem => this.nv = elem} className="slider" data-slider data-initial-start="50">
<span className="slider-handle" data-slider-handle role="slider" tabindex="1" aria-controls="sliderOutput1"></span>
<span className="slider-fill" data-slider-fill></span>
</div>
</div>
<div className="range-slider__value">
<input type="number" id="sliderOutput1" />
</div>
</div>
);
}
}
export default SearchRangeFilter;
By running $("#sliderOutput1").val()
in my browser's console I can see that when I move the slider, the hidden input's value is changing. However handleSliderMove()
is never getting called.
What am I doing wrong?