base-ui
base-ui copied to clipboard
[Slider] Formatting API for the value displayed in `Slider.Output`
Extension of https://github.com/mui/base-ui/issues/216
A format
API/prop for slider could support these two cases:
1. Intl.NumberFormatOptions
For parity with NumberField
:
<Slider.Root defaultValue={[50, 70]}>
<Slider.Output format={{ style: 'currency', currency: 'USD' }} />
{/* other subcomponents */}
<Slider.Root>
renders
<output>$50.00 – $70.00</output>
2. Custom function
To support formats that are not provided by the Intl
API, example:
<Slider.Root defaultValue={[50, 70]}>
<Slider.Output format={(values) => `${values.map(val => `${val}`).join(' – ')}°C`} />
{/* other subcomponents */}
<Slider.Root>
renders
<output>50 – 70°C</output>
Search keywords: