From bdb22927cf755deff5cfd43f4375caa90a1e8e68 Mon Sep 17 00:00:00 2001 From: Ryan Haig Date: Wed, 5 Apr 2023 10:42:45 -0600 Subject: [PATCH] ci: inverted sliders, honor inverted key down handler for horizontal sliders --- src/components/ReactSlider/ReactSlider.jsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/ReactSlider/ReactSlider.jsx b/src/components/ReactSlider/ReactSlider.jsx index de9dd21..08a0b0c 100644 --- a/src/components/ReactSlider/ReactSlider.jsx +++ b/src/components/ReactSlider/ReactSlider.jsx @@ -824,14 +824,28 @@ class ReactSlider extends React.Component { moveUpByStep(step = this.props.step) { const oldValue = this.state.value[this.state.index]; - const newValue = trimAlignValue(oldValue + step, this.props); - this.move(Math.min(newValue, this.props.max)); + + // if the slider is inverted and horizontal we want to honor the inverted value + const newValue = + this.props.invert && this.props.orientation === 'horizontal' + ? oldValue - step + : oldValue + step; + + const trimAlign = trimAlignValue(newValue, this.props); + this.move(Math.min(trimAlign, this.props.max)); } moveDownByStep(step = this.props.step) { const oldValue = this.state.value[this.state.index]; - const newValue = trimAlignValue(oldValue - step, this.props); - this.move(Math.max(newValue, this.props.min)); + + // if the slider is inverted and horizontal we want to honor the inverted value + const newValue = + this.props.invert && this.props.orientation === 'horizontal' + ? oldValue + step + : oldValue - step; + + const trimAlign = trimAlignValue(newValue, this.props); + this.move(Math.max(trimAlign, this.props.min)); } move(newValue) {