Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Adding drag_value to Slider #888

Merged
merged 24 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d1505e8
First stab at adding drag_value to Slider
almarklein Nov 17, 2020
704a844
Make an initial fire of drag_value with the value of 'value'
almarklein Dec 1, 2020
e74b519
update updatemode docs
almarklein Dec 1, 2020
cbd7d22
Implement drag_value for RangeSlider
almarklein Dec 2, 2020
04dfd98
lint
almarklein Dec 2, 2020
c7adc18
Update src/components/Slider.react.js
almarklein Dec 3, 2020
f67f75c
add tests for slider
almarklein Dec 10, 2020
fa6379f
Merge branch 'drag_value2' of github.com:almarklein/dash-core-compone…
almarklein Dec 10, 2020
4763f78
lint and add missing import
almarklein Dec 10, 2020
966f227
black?
almarklein Dec 10, 2020
4d0a3e2
fix test, hopefully
almarklein Dec 10, 2020
a0740c2
fix test
almarklein Dec 10, 2020
7ddd835
fix test
almarklein Dec 10, 2020
b9c72c4
fix test?
almarklein Dec 10, 2020
0799af5
fix?
almarklein Dec 10, 2020
1be148f
use exact same code as other example. Im running out of ideas
almarklein Dec 10, 2020
b3ccc08
bring test down to minimum
almarklein Dec 10, 2020
24600cf
also include output for value
almarklein Dec 10, 2020
82c8763
refactor slicer implementation a bit
almarklein Dec 11, 2020
4c19122
change test and tweak code
almarklein Dec 11, 2020
773c881
maybe only the initialization fails?
almarklein Dec 11, 2020
65a1ba0
Merge branch 'dev' into drag_value2
Marc-Andre-Rivet Dec 11, 2020
1322548
update rangeslider and add a test for it
almarklein Dec 11, 2020
6c9bcda
verify that `value` only changes on mouseup while `drag_value` change…
alexcjohnson Dec 14, 2020
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
21 changes: 13 additions & 8 deletions src/components/RangeSlider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ RangeSlider.propTypes = {
*/
value: PropTypes.arrayOf(PropTypes.number),

/**
* The value of the input during a drag
*/
drag_value: PropTypes.arrayOf(PropTypes.number),

/**
* allowCross could be set as true to allow those handles to cross.
*/
Expand Down Expand Up @@ -145,18 +150,18 @@ RangeSlider.propTypes = {
verticalHeight: PropTypes.number,

/**
* Determines when the component should update
* its value. If `mouseup`, then the slider
* will only trigger its value when the user has
* finished dragging the slider. If `drag`, then
* the slider will update its value continuously
* as it is being dragged.
* Only use `drag` if your updates are fast.
* Determines when the component should update its `value`
* property. If `mouseup` (the default) then the slider
* will only trigger its value when the user has finished
* dragging the slider. If `drag`, then the slider will
* update its value continuously as it is being dragged.
* Note that for the latter case, the `drag_value`
* property could be used instead.
*/
updatemode: PropTypes.oneOf(['mouseup', 'drag']),

/**
* Dash-assigned callback that gets fired when the value changes.
* Dash-assigned callback that gets fired when the value or drag_value changes.
*/
setProps: PropTypes.func,

Expand Down
21 changes: 13 additions & 8 deletions src/components/Slider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ Slider.propTypes = {
*/
value: PropTypes.number,

/**
* The value of the input during a drag
*/
drag_value: PropTypes.number,

/**
* Additional CSS class for the root DOM node
*/
Expand Down Expand Up @@ -125,18 +130,18 @@ Slider.propTypes = {
verticalHeight: PropTypes.number,

/**
* Determines when the component should update
* its value. If `mouseup`, then the slider
* will only trigger its value when the user has
* finished dragging the slider. If `drag`, then
* the slider will update its value continuously
* as it is being dragged.
* Only use `drag` if your updates are fast.
* Determines when the component should update its `value`
* property. If `mouseup` (the default) then the slider
* will only trigger its value when the user has finished
* dragging the slider. If `drag`, then the slider will
* update its value continuously as it is being dragged.
* Note that for the latter case, the `drag_value`
* property could be used instead.
almarklein marked this conversation as resolved.
Show resolved Hide resolved
*/
updatemode: PropTypes.oneOf(['mouseup', 'drag']),

/**
* Dash-assigned callback that gets fired when the value changes.
* Dash-assigned callback that gets fired when the value or drag_value changes.
*/
setProps: PropTypes.func,

Expand Down
10 changes: 7 additions & 3 deletions src/fragments/RangeSlider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export default class RangeSlider extends Component {
this._computeStyle = computeSliderStyle();
this.state = {
value: props.value,
drag_value: props.value,
};
this.props.setProps({drag_value: props.value});
}

propsToState(newProps) {
if (newProps.value !== this.props.value) {
this.setState({value: newProps.value});
this.setState({value: newProps.value, drag_value: newProps.value});
}
}

Expand Down Expand Up @@ -84,9 +86,10 @@ export default class RangeSlider extends Component {
<this.DashSlider
onChange={value => {
if (updatemode === 'drag') {
setProps({value});
setProps({value: value, drag_value: value});
} else {
this.setState({value});
this.setState({value: value});
setProps({drag_value: value});
}
}}
onAfterChange={value => {
Expand All @@ -101,6 +104,7 @@ export default class RangeSlider extends Component {
[
'className',
'value',
'drag_value',
'setProps',
'marks',
'updatemode',
Expand Down
10 changes: 7 additions & 3 deletions src/fragments/Slider.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ export default class Slider extends Component {
this._computeStyle = computeSliderStyle();
this.state = {
value: props.value,
drag_value: props.value,
almarklein marked this conversation as resolved.
Show resolved Hide resolved
};
this.props.setProps({drag_value: props.value});
}

propsToState(newProps) {
if (newProps.value !== this.props.value) {
this.setState({value: newProps.value});
this.setState({value: newProps.value, drag_value: newProps.value});
}
}

Expand Down Expand Up @@ -87,9 +89,10 @@ export default class Slider extends Component {
<this.DashSlider
onChange={value => {
if (updatemode === 'drag') {
setProps({value});
setProps({value: value, drag_value: value});
} else {
this.setState({value});
this.setState({value: value});
setProps({drag_value: value});
}
}}
onAfterChange={value => {
Expand All @@ -114,6 +117,7 @@ export default class Slider extends Component {
'setProps',
'updatemode',
'value',
'drag_value',
'marks',
'verticalHeight',
],
Expand Down