From 53b2334152eabe7f808e1840a3d64db4109e4103 Mon Sep 17 00:00:00 2001 From: AmbrishRamachandiran Date: Wed, 4 Mar 2026 16:43:21 +0530 Subject: [PATCH] Fix review comments Signed-off-by: AmbrishRamachandiran --- .../components/RangeSlider/RangeSlider.tsx | 82 ++++++++++++------- .../ui/src/components/RangeSlider/types.ts | 4 +- 2 files changed, 56 insertions(+), 30 deletions(-) diff --git a/packages/ui/src/components/RangeSlider/RangeSlider.tsx b/packages/ui/src/components/RangeSlider/RangeSlider.tsx index fd9f048a86..ef100dda65 100644 --- a/packages/ui/src/components/RangeSlider/RangeSlider.tsx +++ b/packages/ui/src/components/RangeSlider/RangeSlider.tsx @@ -46,14 +46,30 @@ export const RangeSlider = forwardRef( } }, [label, ariaLabel, ariaLabelledBy]); + useEffect(() => { + const valueArray = props.value ?? props.defaultValue; + if (valueArray && valueArray.length !== 2) { + console.error( + `RangeSlider requires exactly 2 values [min, max], but received ${valueArray.length} values`, + ); + } + }, [props.value, props.defaultValue]); + + const minValue = props.minValue ?? 0; + const maxValue = props.maxValue ?? 100; + const { + defaultValue = [minValue, maxValue] as [number, number], + ...propsWithoutDefault + } = props; + const { classNames, dataAttributes, style, cleanedProps } = useStyles( RangeSliderDefinition, { - minValue: 0, - maxValue: 100, + minValue, + maxValue, step: 1, - defaultValue: [0, 100], - ...props, + defaultValue, + ...propsWithoutDefault, }, ); @@ -106,30 +122,40 @@ export const RangeSlider = forwardRef( - {({ state }) => ( - <> -
- - - - )} + {({ state }) => { + const start = state.getThumbPercent(0); + const end = state.getThumbPercent(1); + const rangePercent = (end - start) * 100; + const isVertical = state.orientation === 'vertical'; + const trackFillStyle = isVertical + ? { + bottom: `${start * 100}%`, + height: `${rangePercent}%`, + } + : { + left: `${start * 100}%`, + width: `${rangePercent}%`, + }; + return ( + <> +
+ + + + ); + }} diff --git a/packages/ui/src/components/RangeSlider/types.ts b/packages/ui/src/components/RangeSlider/types.ts index 3054a2ebbe..ad93f7c9d4 100644 --- a/packages/ui/src/components/RangeSlider/types.ts +++ b/packages/ui/src/components/RangeSlider/types.ts @@ -19,10 +19,10 @@ import type { FieldLabelProps } from '../FieldLabel/types'; /** @public */ export interface RangeSliderProps - extends Omit, 'children'>, + extends Omit, 'children'>, Omit { /** - * Whether to show value labels above the thumbs + * Whether to show a value label in the header next to the field label * @defaultValue false */ showValueLabel?: boolean;