Skip to content

Commit d2d46ca

Browse files
devongovettGitHub Enterprise
authored andcommitted
Fix ColorSlider and RangeSlider bugs (#190)
1 parent af3f5c4 commit d2d46ca

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

packages/@react-spectrum/s2/src/ColorSlider.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import {
1414
ColorSlider as AriaColorSlider,
1515
ColorSliderProps as AriaColorSliderProps,
1616
SliderOutput,
17-
SliderTrack
17+
SliderTrack,
18+
useLocale
1819
} from 'react-aria-components';
1920
import {FieldLabel} from './Field';
2021
import {style} from '../style/spectrum-theme' with {type: 'macro'};
@@ -32,6 +33,8 @@ function ColorSlider(props: ColorSliderProps, ref: DOMRef<HTMLDivElement>) {
3233
let {UNSAFE_className = '', UNSAFE_style, styles} = props;
3334
let containerRef = useDOMRef(ref);
3435
let trackRef = useRef(null);
36+
let {locale} = useLocale();
37+
3538
return (
3639
<AriaColorSlider
3740
{...props}
@@ -64,9 +67,15 @@ function ColorSlider(props: ColorSliderProps, ref: DOMRef<HTMLDivElement>) {
6467
rowGap: 4
6568
}, getAllowedOverrides())(renderProps, styles)}>
6669
{({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+
)}
7079
{orientation === 'horizontal' &&
7180
<SliderOutput
7281
className={style({

packages/@react-spectrum/s2/src/RangeSlider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function RangeSlider(props: RangeSliderProps, ref: FocusableRef<HTMLDivElement>)
5555
<SliderBase
5656
{...props}
5757
value={props.value ? [props.value.start, props.value.end] : undefined}
58-
defaultValue={props.defaultValue ? [props.defaultValue.start, props.defaultValue.end] : undefined}
58+
defaultValue={props.defaultValue ? [props.defaultValue.start, props.defaultValue.end] : [props.minValue ?? 0, props.maxValue ?? 100]}
5959
onChange={v => props.onChange?.({start: v[0], end: v[1]})}
6060
onChangeEnd={v => props.onChangeEnd?.({start: v[0], end: v[1]})}
6161
sliderRef={domRef}>

0 commit comments

Comments
 (0)