diff --git a/docs/data/components/slider/RangeSlider.js b/docs/data/components/slider/RangeSlider.js index 5a7ce98296..cb2225a840 100644 --- a/docs/data/components/slider/RangeSlider.js +++ b/docs/data/components/slider/RangeSlider.js @@ -31,7 +31,7 @@ export default function RangeSlider() { Controlled Range - + @@ -49,7 +49,7 @@ export default function RangeSlider() { Uncontrolled Range - + diff --git a/docs/data/components/slider/RangeSlider.tsx b/docs/data/components/slider/RangeSlider.tsx index 829473631e..6c8cda99bf 100644 --- a/docs/data/components/slider/RangeSlider.tsx +++ b/docs/data/components/slider/RangeSlider.tsx @@ -31,7 +31,7 @@ export default function RangeSlider() { Controlled Range - + @@ -49,7 +49,7 @@ export default function RangeSlider() { Uncontrolled Range - + diff --git a/docs/data/components/slider/RtlSlider.js b/docs/data/components/slider/RtlSlider.js index 0debd7cac1..3d5a175442 100644 --- a/docs/data/components/slider/RtlSlider.js +++ b/docs/data/components/slider/RtlSlider.js @@ -28,7 +28,7 @@ export default function RtlSlider() { > Volume (RTL) - + diff --git a/docs/data/components/slider/RtlSlider.tsx b/docs/data/components/slider/RtlSlider.tsx index 7ed0c2f0a7..57f2d3a9fd 100644 --- a/docs/data/components/slider/RtlSlider.tsx +++ b/docs/data/components/slider/RtlSlider.tsx @@ -27,7 +27,7 @@ export default function RtlSlider() { > Volume (RTL) - + diff --git a/docs/data/components/slider/UnstyledSliderIntroduction/css-modules/index.js b/docs/data/components/slider/UnstyledSliderIntroduction/css-modules/index.js index 76efe0d309..5ec46720bd 100644 --- a/docs/data/components/slider/UnstyledSliderIntroduction/css-modules/index.js +++ b/docs/data/components/slider/UnstyledSliderIntroduction/css-modules/index.js @@ -25,7 +25,7 @@ export default function UnstyledSliderIntroduction() { > Volume - + diff --git a/docs/data/components/slider/UnstyledSliderIntroduction/css-modules/index.tsx b/docs/data/components/slider/UnstyledSliderIntroduction/css-modules/index.tsx index c753397f4e..f8bb6c3cf9 100644 --- a/docs/data/components/slider/UnstyledSliderIntroduction/css-modules/index.tsx +++ b/docs/data/components/slider/UnstyledSliderIntroduction/css-modules/index.tsx @@ -24,7 +24,7 @@ export default function UnstyledSliderIntroduction() { > Volume - + diff --git a/docs/data/components/slider/UnstyledSliderIntroduction/system/index.js b/docs/data/components/slider/UnstyledSliderIntroduction/system/index.js index d03e16db26..55013a9be6 100644 --- a/docs/data/components/slider/UnstyledSliderIntroduction/system/index.js +++ b/docs/data/components/slider/UnstyledSliderIntroduction/system/index.js @@ -69,7 +69,7 @@ const Slider = styled(BaseSlider.Root)` gap: 1rem; `; -const SliderOutput = styled(BaseSlider.Output)` +const SliderOutput = styled(BaseSlider.Value)` text-align: right; `; diff --git a/docs/data/components/slider/UnstyledSliderIntroduction/system/index.tsx b/docs/data/components/slider/UnstyledSliderIntroduction/system/index.tsx index 4e82270683..fd2c9c1a32 100644 --- a/docs/data/components/slider/UnstyledSliderIntroduction/system/index.tsx +++ b/docs/data/components/slider/UnstyledSliderIntroduction/system/index.tsx @@ -63,7 +63,7 @@ const Slider = styled(BaseSlider.Root)` gap: 1rem; `; -const SliderOutput = styled(BaseSlider.Output)` +const SliderOutput = styled(BaseSlider.Value)` text-align: right; `; diff --git a/docs/data/components/slider/UnstyledSliderIntroduction/tailwind/index.js b/docs/data/components/slider/UnstyledSliderIntroduction/tailwind/index.js index 4b72e9a1cd..f77ea7b7db 100644 --- a/docs/data/components/slider/UnstyledSliderIntroduction/tailwind/index.js +++ b/docs/data/components/slider/UnstyledSliderIntroduction/tailwind/index.js @@ -65,7 +65,7 @@ Slider.propTypes = { const SliderOutput = React.forwardRef(function SliderOutput(props, ref) { return ( - diff --git a/docs/data/components/slider/UnstyledSliderIntroduction/tailwind/index.tsx b/docs/data/components/slider/UnstyledSliderIntroduction/tailwind/index.tsx index d24bb7db52..38ea928cb5 100644 --- a/docs/data/components/slider/UnstyledSliderIntroduction/tailwind/index.tsx +++ b/docs/data/components/slider/UnstyledSliderIntroduction/tailwind/index.tsx @@ -58,11 +58,11 @@ const Slider = React.forwardRef(function Slider( }); const SliderOutput = React.forwardRef(function SliderOutput( - props: BaseSlider.Output.Props, + props: BaseSlider.Value.Props, ref: React.ForwardedRef, ) { return ( - diff --git a/docs/data/components/slider/VerticalSlider.js b/docs/data/components/slider/VerticalSlider.js index 9fd1d7bdba..d36fe52c3f 100644 --- a/docs/data/components/slider/VerticalSlider.js +++ b/docs/data/components/slider/VerticalSlider.js @@ -32,7 +32,7 @@ export default function VerticalSlider() { /> - + ); diff --git a/docs/data/components/slider/VerticalSlider.tsx b/docs/data/components/slider/VerticalSlider.tsx index 211592e5cf..767b477c0c 100644 --- a/docs/data/components/slider/VerticalSlider.tsx +++ b/docs/data/components/slider/VerticalSlider.tsx @@ -31,7 +31,7 @@ export default function VerticalSlider() { /> - + ); diff --git a/docs/data/components/slider/slider.mdx b/docs/data/components/slider/slider.mdx index b08b5f85c2..2f5887b8ec 100644 --- a/docs/data/components/slider/slider.mdx +++ b/docs/data/components/slider/slider.mdx @@ -2,8 +2,8 @@ productId: base-ui title: React Slider components description: The Slider component provides users with an input for a one or more numerical values within a given range. -components: SliderRoot, SliderOutput, SliderControl, SliderTrack, SliderThumb, SliderIndicator -hooks: useSliderRoot, useSliderOutput, useSliderControl, useSliderThumb, useSliderIndicator +components: SliderRoot, SliderValue, SliderControl, SliderTrack, SliderThumb, SliderIndicator +hooks: useSliderRoot, useSliderValue, useSliderControl, useSliderThumb, useSliderIndicator githubLabel: 'component: slider' waiAria: https://www.w3.org/WAI/ARIA/apg/patterns/slider-multithumb/ packageName: '@base-ui-components/react' @@ -26,7 +26,7 @@ packageName: '@base-ui-components/react' Sliders are implemented using a collection of related components: - `` is a top-level component that wraps the other components. -- `` renders the value of the slider. +- `` renders the value of the slider. - `` renders the click/touch area that contains the track and thumb. - `` renders the visible rail on the `Control` along which the thumb(s) can be moved. - `` renders the filled portion of the track which represents the value(s). @@ -34,7 +34,7 @@ Sliders are implemented using a collection of related components: ```tsx - + @@ -54,7 +54,7 @@ When Slider is uncontrolled, the `defaultValue` prop sets the initial value of t function App() { return ( - + @@ -78,7 +78,7 @@ function App() { const [value, setValue] = useState(50); return ( - + @@ -98,7 +98,7 @@ The `min` and `max` props can be used to restrict the value(s) within a range. ```tsx - + @@ -114,7 +114,7 @@ The `step` prop snaps each value to multiples of the given number. In the below ```tsx - + @@ -132,7 +132,7 @@ To let users set the start and end of a range on a Slider, provide an array of v ```tsx - + diff --git a/docs/reference/generated/slider-root.json b/docs/reference/generated/slider-root.json index 53dfe629a3..493fcf4c0b 100644 --- a/docs/reference/generated/slider-root.json +++ b/docs/reference/generated/slider-root.json @@ -19,6 +19,10 @@ "default": "false", "description": "Whether the component should ignore user interaction." }, + "format": { + "type": "Intl.NumberFormatOptions", + "description": "Options to format the input value." + }, "largeStep": { "type": "number", "default": "10", diff --git a/docs/reference/generated/slider-thumb.json b/docs/reference/generated/slider-thumb.json index 2679c77616..194be301bf 100644 --- a/docs/reference/generated/slider-thumb.json +++ b/docs/reference/generated/slider-thumb.json @@ -19,7 +19,7 @@ "description": "Accepts a function which returns a string value that provides a user-friendly name for the input associated with the thumb" }, "getAriaValueText": { - "type": "function(value: number, index: number) => string", + "type": "function(formattedValue: string, value: number, index: number) => string", "description": "Accepts a function which returns a string value that provides a user-friendly name for the current value of the slider.\nThis is important for screen reader users." }, "render": { diff --git a/docs/reference/generated/slider-output.json b/docs/reference/generated/slider-value.json similarity index 96% rename from docs/reference/generated/slider-output.json rename to docs/reference/generated/slider-value.json index 19eac9b862..e9a468f183 100644 --- a/docs/reference/generated/slider-output.json +++ b/docs/reference/generated/slider-value.json @@ -1,5 +1,5 @@ { - "name": "SliderOutput", + "name": "SliderValue", "description": "Displays the current value of the slider as text.\nRenders an `` element.", "props": { "className": { diff --git a/docs/reference/overrides/slider-root.json b/docs/reference/overrides/slider-root.json index 673bdceab5..2d4ec7f1de 100644 --- a/docs/reference/overrides/slider-root.json +++ b/docs/reference/overrides/slider-root.json @@ -1,6 +1,9 @@ { "name": "SliderRoot", "props": { + "format": { + "type": "Intl.NumberFormatOptions" + }, "onValueChange": { "type": "(value, event, activeThumbIndex) => void" }, diff --git a/docs/src/app/(private)/experiments/slider-change-committed-lag.tsx b/docs/src/app/(private)/experiments/slider-change-committed-lag.tsx index 5ccb72aeb6..b8562483a8 100644 --- a/docs/src/app/(private)/experiments/slider-change-committed-lag.tsx +++ b/docs/src/app/(private)/experiments/slider-change-committed-lag.tsx @@ -22,7 +22,7 @@ export default function App() { onValueChange={(newValue) => setVal1(newValue as number)} onValueCommitted={(newValue) => setVal2(newValue as number)} > - + diff --git a/docs/src/app/(private)/experiments/slider-format.tsx b/docs/src/app/(private)/experiments/slider-format.tsx new file mode 100644 index 0000000000..26756bcee8 --- /dev/null +++ b/docs/src/app/(private)/experiments/slider-format.tsx @@ -0,0 +1,56 @@ +'use client'; +import * as React from 'react'; +import { useTheme } from '@mui/system'; +import { Slider } from '@base-ui-components/react/slider'; +import c from './slider.module.css'; + +export default function UnstyledSliderIntroduction() { + // Replace this with your app logic for determining dark mode + const isDarkMode = useIsDarkMode(); + return ( +
+ + + + {(_, values) => `$${values[0].toFixed(2)} - ${values[1].toFixed(2)} USD`} + + + + + + + + + +
+ ); +} + +function Label(props: React.LabelHTMLAttributes) { + const { id, htmlFor, ...otherProps } = props; + + return