@@ -14,7 +14,8 @@ import {
14
14
ColorSlider as AriaColorSlider ,
15
15
ColorSliderProps as AriaColorSliderProps ,
16
16
SliderOutput ,
17
- SliderTrack
17
+ SliderTrack ,
18
+ useLocale
18
19
} from 'react-aria-components' ;
19
20
import { FieldLabel } from './Field' ;
20
21
import { style } from '../style/spectrum-theme' with { type : 'macro' } ;
@@ -32,6 +33,8 @@ function ColorSlider(props: ColorSliderProps, ref: DOMRef<HTMLDivElement>) {
32
33
let { UNSAFE_className = '' , UNSAFE_style, styles} = props ;
33
34
let containerRef = useDOMRef ( ref ) ;
34
35
let trackRef = useRef ( null ) ;
36
+ let { locale} = useLocale ( ) ;
37
+
35
38
return (
36
39
< AriaColorSlider
37
40
{ ...props }
@@ -64,9 +67,15 @@ function ColorSlider(props: ColorSliderProps, ref: DOMRef<HTMLDivElement>) {
64
67
rowGap : 4
65
68
} , getAllowedOverrides ( ) ) ( renderProps , styles ) } >
66
69
{ ( { isDisabled, orientation, state} ) => ( < >
67
- { orientation === 'horizontal' && props . label &&
68
- < FieldLabel isDisabled = { isDisabled } contextualHelp = { props . contextualHelp } > { props . label } </ FieldLabel >
69
- }
70
+ { orientation === 'horizontal' && ( props . label || ( props . label === undefined && ! props [ 'aria-label' ] && ! props [ 'aria-labelledby' ] ) ) && (
71
+ // If no external label, aria-label or aria-labelledby is provided,
72
+ // default to displaying the localized channel value.
73
+ // Specifically check if label is undefined. If label is `null` then display no visible label.
74
+ // A default aria-label is provided by useColorSlider in that case.
75
+ < FieldLabel isDisabled = { isDisabled } contextualHelp = { props . contextualHelp } >
76
+ { props . label || state . value . getChannelName ( props . channel , locale ) }
77
+ </ FieldLabel >
78
+ ) }
70
79
{ orientation === 'horizontal' &&
71
80
< SliderOutput
72
81
className = { style ( {
0 commit comments