react-spectrum icon indicating copy to clipboard operation
react-spectrum copied to clipboard

RAC Slider should support custom formatters

Open staticshock opened this issue 2 weeks ago โ€ข 1 comments

Provide a general summary of the feature here

Slider has a formatOptions prop, which is constrained to Intl.NumberFormat values. I find this puzzling: I'd like to produce a thumb label of "10 teachers", but with the current constraint I can only produce one that uses one of the supported unit identifiers, e.g. "10 hours" or "10 stones".

๐Ÿค” Expected Behavior?

There's a bunch of existing machinery in sliders that lets you turn a number into a label using a preconfigured formatter:

<Slider formatOptions={{ style: 'unit', unit: 'hour' }}>
  <SliderTrack>
    {({ state }) =>
      state.values.map((_, ix) => (
        <SliderThumb
          aria-label={state.getThumbValueLabel(ix)}
          index={ix}
          key={ix}
        />
      ))
    }
  </SliderTrack>
</Slider>

๐Ÿ˜ฏ Current Behavior

The fact that I can use the existing plumbing is great. Unfortunately, it also feels unnecessarily rigid. If I want my own noun in the output, I have to bypass all the available plumbing and handroll an alternative.

๐Ÿ’ Possible Solution

Maybe in addition to formatOptions, support a formatter function?

๐Ÿ”ฆ Context

I ran into this issue working on a pricing slider for a product checkout flow.

๐Ÿ’ป Examples

No response

๐Ÿงข Your Company/Team

No response

๐Ÿ•ท Tracking Issue

No response

staticshock avatar Nov 27 '25 07:11 staticshock