Sliders aria-valuetext should match output element
- Dominant language
- TypeScript
- Stars
- 15.9k
- Forks
- 1.6k
- Avg merge
- 3d 9m
- Merged PRs (30d)
- 59
Description
### Discussed in https://github.com/adobe/react-spectrum/discussions/6401
Originally posted by **robin-kestrel** May 17, 2024
The `Slider` component currently accepts a `formatOptions` prop; if specified, it is used in conjunction with `Intl.NumberFormat` to (a) set the content of the `SliderOutput` component and (b) set the `aria-valuetext` property on the `input` hidden inside each `Thumb` component.
This API is perfectly fine for simple cases, but seems limiting for more complex ones. [Here's a sandbox with some motivating examples.](https://codesandbox.io/p/devbox/recursing-dubinsky-77kpw7?file=%2Fsrc%2FApp.tsx%3A4%2C10) The first group of sliders shows what is currently possible; the second group of sliders shows what I think is _almost_ currently possible. Replacing the `SliderOutput` component with a custom label is trivial, but propagating that label to the `aria-valuetext` property of the corresponding input doesn't seem like it's currently doable — at least, not without a lot of messing around with hooks.
Is there an option I'm missing that would allow custom labels to be propagated to `aria-valuetext`, for screen readers to pick up? If not, could such an option be added? The simplest thing that comes to mind is a `format` prop for the `Slider` component that would accept a `(value: number) => string`, and would otherwise function basically the same way as `formatOptions` does now.
@snowystinger : I chatted with our accessibility team and they agree, it'd be nice if the aria-valuetext matched the output element. This may be difficult because the output accepts a ReactNode. The API will need some thought.
Contributor guide
Assessment
This issue has not been assessed yet.