Material-ui: [Slider] onDragStop and onDragStart events have no value

Created on 8 Aug 2016  路  5Comments  路  Source: mui-org/material-ui

Problem description

One cannot access the Slider's value on events onDragStop and onDragStart.
Edit: neither does onMouseUp work. Only onChange gets the event value attached.

I did injectTapEventPlugin();.

Steps to reproduce

<Slider onDragStop={this.onTest} ... />

onTest(e, value) {
    console.log(e, value, e.target.value)
}  

Returns: Event, undefined, undefined.

Versions

  • Material-UI: 0.15.2
  • React: 15.2.1
  • Browser: Chrome
Slider v0.x

Most helpful comment

This is onChange in your example. onChange works fine. onDragStop does not.

All 5 comments

I think is you event bind wrong.

I wrote a demo for you, and the value is right.

import React from 'react';
import Slider from '../src/Slider';

import injectTapEventPlugin from 'react-tap-event-plugin';

// Needed for onTouchTap
// http://stackoverflow.com/a/34015469/988941
injectTapEventPlugin();

/**
 * `SelectField` supports a floating label with the `floatingLabelText` property. This can be fixed in place with the
 * `floatingLabelFixed property, and can be customised with the `floatingLabelText` property.
 */
export default class App extends React.Component {
  constructor(props) {
    super(props);
  }

  changeSlider(event, value) {
    console.log(value);
  }

  render() {
    return (
      <Slider
        defaultValue={1}
        onChange={(event, value) => this.changeSlider(event, value)}
      />
    );
  }
}

This is onChange in your example. onChange works fine. onDragStop does not.

I have this use-case where the slider's value is changed with a timer (setInterval) but it can be changed by the user if he slides the slider, the problem is that i want to catch the change of the value only if the user slides the slider and this is impossible right now :( because the event we get from onDragStop doesn't have a value attribute.

We plan on migrating the component to the v1-beta branch. I'm closing the issue for #4793.

Was this page helpful?
0 / 5 - 0 ratings