Skip to content

Commit

Permalink
fix(Slider): make it optional to provide an updated prop value
Browse files Browse the repository at this point in the history
  • Loading branch information
tujoworker committed Aug 30, 2022
1 parent fcdf9f8 commit b558992
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/dnb-eufemia/src/components/slider/SliderProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ export function SliderProvider(localProps: SliderProps) {
} = allProps

const [value, setValue] = React.useState<ValueTypes>(_value)
const [exterValue, updateExternValue] =
React.useState<ValueTypes>(_value)
const realtimeValue = React.useRef<ValueTypes>(_value)
const [thumbState, setThumbState] =
React.useState<ThumbStateEnums>('initial')
Expand Down Expand Up @@ -215,14 +217,16 @@ export function SliderProvider(localProps: SliderProps) {
React.useEffect(() => {
if (isMulti) {
const hasChanged = (_value as Array<number>).some((val, i) => {
return val !== value[i]
return val !== exterValue[i]
})

if (hasChanged) {
updateValue(_value)
updateExternValue(_value)
}
} else {
} else if (_value !== exterValue) {
updateValue(_value)
updateExternValue(_value)
}

// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit b558992

Please sign in to comment.