base-ui icon indicating copy to clipboard operation
base-ui copied to clipboard

[Slider] Formatting API for the value displayed in `Slider.Output`

Open mj12albert opened this issue 8 months ago • 0 comments

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:

mj12albert avatar Jun 18 '24 13:06 mj12albert