diff --git a/.yarn/versions/b20a66e3.yml b/.yarn/versions/b20a66e3.yml
new file mode 100644
index 000000000..a1a6a4eed
--- /dev/null
+++ b/.yarn/versions/b20a66e3.yml
@@ -0,0 +1,5 @@
+releases:
+ "@radix-ui/react-slider": minor
+
+declined:
+ - primitives
diff --git a/packages/react/slider/src/Slider.stories.tsx b/packages/react/slider/src/Slider.stories.tsx
index 66b3d0e24..529bcc78f 100644
--- a/packages/react/slider/src/Slider.stories.tsx
+++ b/packages/react/slider/src/Slider.stories.tsx
@@ -262,10 +262,20 @@ export const SmallSteps = () => {
};
export const WithinForm = () => {
- const [data, setData] = React.useState({ single: [0], multiple: [10, 15, 20, 80] });
+ const [data, setData] = React.useState({
+ single: [0],
+ multiple: [10, 15, 20, 80],
+ price: {
+ min: 30,
+ max: 70,
+ },
+ });
return (
);
};
diff --git a/packages/react/slider/src/Slider.tsx b/packages/react/slider/src/Slider.tsx
index 62751cf11..69bab3511 100644
--- a/packages/react/slider/src/Slider.tsx
+++ b/packages/react/slider/src/Slider.tsx
@@ -41,6 +41,7 @@ const [createSliderContext, createSliderScope] = createContextScope(SLIDER_NAME,
]);
type SliderContextValue = {
+ name?: string;
disabled?: boolean;
min: number;
max: number;
@@ -90,13 +91,9 @@ const Slider = React.forwardRef(
inverted = false,
...sliderProps
} = props;
- const [slider, setSlider] = React.useState(null);
- const composedRefs = useComposedRefs(forwardedRef, (node) => setSlider(node));
const thumbRefs = React.useRef(new Set());
const valueIndexToChangeRef = React.useRef(0);
const isHorizontal = orientation === 'horizontal';
- // We set this to true by default so that events bubble to forms without JS (SSR)
- const isFormControl = slider ? Boolean(slider.closest('form')) : true;
const SliderOrientation = isHorizontal ? SliderHorizontal : SliderVertical;
const [values = [], setValues] = useControllableState({
@@ -147,6 +144,7 @@ const Slider = React.forwardRef(
return (
(
aria-disabled={disabled}
data-disabled={disabled ? '' : undefined}
{...sliderProps}
- ref={composedRefs}
+ ref={forwardedRef}
onPointerDown={composeEventHandlers(sliderProps.onPointerDown, () => {
if (!disabled) valuesBeforeSlideStartRef.current = values;
})}
@@ -189,14 +187,6 @@ const Slider = React.forwardRef(
/>
- {isFormControl &&
- values.map((value, index) => (
- 1 ? '[]' : '') : undefined}
- value={value}
- />
- ))}
);
}
@@ -556,15 +546,18 @@ const SliderThumb = React.forwardRef(
type SliderThumbImplElement = React.ElementRef;
interface SliderThumbImplProps extends PrimitiveSpanProps {
index: number;
+ name?: string;
}
const SliderThumbImpl = React.forwardRef(
(props: ScopedProps, forwardedRef) => {
- const { __scopeSlider, index, ...thumbProps } = props;
+ const { __scopeSlider, index, name, ...thumbProps } = props;
const context = useSliderContext(THUMB_NAME, __scopeSlider);
const orientation = useSliderOrientationContext(THUMB_NAME, __scopeSlider);
const [thumb, setThumb] = React.useState(null);
const composedRefs = useComposedRefs(forwardedRef, (node) => setThumb(node));
+ // We set this to true by default so that events bubble to forms without JS (SSR)
+ const isFormControl = thumb ? Boolean(thumb.closest('form')) : true;
const size = useSize(thumb);
// We cast because index could be `-1` which would return undefined
const value = context.values[index] as number | undefined;
@@ -618,6 +611,17 @@ const SliderThumbImpl = React.forwardRef
+
+ {isFormControl && (
+ 1 ? '[]' : '') : undefined)
+ }
+ value={value}
+ />
+ )}
);
}