Skip to content

Commit e83be7c

Browse files
devongovettMichael Jordandannify
authored
ColorSlider and ColorWheel labeling improvements (#1552)
* ColorSlider, ColorWheel localization strings for color channel names * ColorSlider: refactor i18n into @react-aria package * fix lint errors * ColorSlider: fix additional input labelling issues per code review * ColorSlider: include localized channel name when labelled externally * ColorSlider fix failing unit tests due to console warnings whne useSlider is called without a label * Move default labels into Spectrum and add tests Co-authored-by: Michael Jordan <[email protected]> Co-authored-by: Danni <[email protected]>
1 parent 73d9051 commit e83be7c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+644
-75
lines changed

packages/@react-aria/color/src/useColorSlider.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,22 @@ interface ColorSliderAria {
2929
inputProps: HTMLAttributes<HTMLElement>,
3030
thumbProps: HTMLAttributes<HTMLElement>,
3131
labelProps: HTMLAttributes<HTMLElement>,
32+
outputProps: HTMLAttributes<HTMLElement>,
3233
gradientProps: HTMLAttributes<HTMLElement>
3334
}
3435

3536
export function useColorSlider(props: ColorSliderAriaOptions, state: ColorSliderState): ColorSliderAria {
36-
let {trackRef, orientation, channel} = props;
37+
let {trackRef, inputRef, orientation, channel} = props;
3738

3839
let {direction} = useLocale();
3940

40-
let {groupProps, trackProps, labelProps} = useSlider(props, state, trackRef);
41+
let {groupProps, trackProps, labelProps, outputProps} = useSlider(props, state, trackRef);
4142
let {inputProps, thumbProps} = useSliderThumb({
42-
...props,
43-
index: 0
43+
index: 0,
44+
orientation,
45+
isDisabled: props.isDisabled,
46+
trackRef,
47+
inputRef
4448
}, state);
4549

4650
let generateBackground = () => {
@@ -87,6 +91,7 @@ export function useColorSlider(props: ColorSliderAriaOptions, state: ColorSlider
8791
inputProps,
8892
thumbProps,
8993
labelProps,
94+
outputProps,
9095
gradientProps: {
9196
style: {
9297
background: generateBackground()

packages/@react-aria/color/src/useColorWheel.ts

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
* governing permissions and limitations under the License.
1111
*/
1212

13-
import {ColorWheelProps} from '@react-types/color';
13+
import {AriaColorWheelProps} from '@react-types/color';
1414
import {ColorWheelState} from '@react-stately/color';
15-
import {focusWithoutScrolling, mergeProps, useGlobalListeners} from '@react-aria/utils';
15+
import {focusWithoutScrolling, mergeProps, useGlobalListeners, useLabels} from '@react-aria/utils';
1616
import React, {ChangeEvent, HTMLAttributes, InputHTMLAttributes, RefObject, useCallback, useRef} from 'react';
1717
import {useKeyboard, useMove} from '@react-aria/interactions';
1818

19-
interface ColorWheelAriaProps extends ColorWheelProps {
19+
interface ColorWheelAriaProps extends AriaColorWheelProps {
2020
inputRef: RefObject<HTMLElement>,
2121
containerRef: RefObject<HTMLElement>,
2222
innerRadius: number,
@@ -53,7 +53,14 @@ function cartesianToAngle(x: number, y: number, radius: number): number {
5353
}
5454

5555
export function useColorWheel(props: ColorWheelAriaProps, state: ColorWheelState): ColorWheelAria {
56-
let {inputRef, containerRef, isDisabled, step = 1, innerRadius, outerRadius} = props;
56+
let {
57+
inputRef,
58+
containerRef,
59+
isDisabled,
60+
step = 1,
61+
innerRadius,
62+
outerRadius
63+
} = props;
5764

5865
let {addGlobalListener, removeGlobalListener} = useGlobalListeners();
5966

@@ -192,6 +199,8 @@ export function useColorWheel(props: ColorWheelAriaProps, state: ColorWheelState
192199
}
193200
});
194201

202+
let inputLabellingProps = useLabels(props);
203+
195204
return {
196205
groupProps: isDisabled ? {} : mergeProps({
197206
onMouseDown: (e: React.MouseEvent) => {onTrackDown(undefined, e.pageX, e.pageY);},
@@ -203,18 +212,20 @@ export function useColorWheel(props: ColorWheelAriaProps, state: ColorWheelState
203212
onPointerDown: (e: React.PointerEvent) => {onThumbDown(e.pointerId);},
204213
onTouchStart: (e: React.TouchEvent) => {onThumbDown(e.changedTouches[0].identifier);}
205214
}, movePropsThumb, keyboardProps),
206-
inputProps: {
207-
type: 'range',
208-
'aria-label': 'hue',
209-
min: '0',
210-
max: '360',
211-
step: String(step),
212-
disabled: isDisabled,
213-
value: `${state.value.getChannelValue('hue')}`,
214-
onChange: (e: ChangeEvent<HTMLInputElement>) => {
215-
state.setHue(parseFloat(e.target.value));
215+
inputProps: mergeProps(
216+
inputLabellingProps,
217+
{
218+
type: 'range',
219+
min: '0',
220+
max: '360',
221+
step: String(step),
222+
disabled: isDisabled,
223+
value: `${state.value.getChannelValue('hue')}`,
224+
onChange: (e: ChangeEvent<HTMLInputElement>) => {
225+
state.setHue(parseFloat(e.target.value));
226+
}
216227
}
217-
},
228+
),
218229
thumbPosition: angleToCartesian(state.value.getChannelValue('hue'), thumbRadius)
219230
};
220231
}

packages/@react-aria/color/test/useColorWheel.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ describe('useColorWheel', () => {
7979
let slider = getByRole('slider');
8080

8181
expect(slider).toHaveAttribute('type', 'range');
82-
expect(slider).toHaveAttribute('aria-label', 'hue');
8382
expect(slider).toHaveAttribute('min', '0');
8483
expect(slider).toHaveAttribute('max', '360');
8584
expect(slider).toHaveAttribute('step', '1');
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"hue": "تدرج اللون",
3+
"saturation": "‏‏الإشباع",
4+
"lightness": "الإضاءة",
5+
"brightness": "والقيمة",
6+
"red": "أحمر",
7+
"green": "أخضر",
8+
"blue": "أزرق",
9+
"alpha": "أولي"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"hue": "Нюанс",
3+
"saturation": "Наситеност",
4+
"lightness": "Осветеност",
5+
"brightness": "Яркост",
6+
"red": "Червено",
7+
"green": "Зелено",
8+
"blue": "Синьо",
9+
"alpha": "Алфа"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"hue": "Odstín",
3+
"saturation": "Sytost",
4+
"lightness": "Světlost",
5+
"brightness": "Jas",
6+
"red": "Červená",
7+
"green": "Zelená",
8+
"blue": "Modrá",
9+
"alpha": "Alfa"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"hue": "Nuance",
3+
"saturation": "Mætning",
4+
"lightness": "Lysstyrke",
5+
"brightness": "Værdi",
6+
"red": "Rød",
7+
"green": "Grøn",
8+
"blue": "Blå",
9+
"alpha": "Alfa"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"hue": "Farbton",
3+
"saturation": "Sättigung",
4+
"lightness": "Leuchtkraft",
5+
"brightness": "Helligkeit",
6+
"red": "Rot",
7+
"green": "Grün",
8+
"blue": "Blau",
9+
"alpha": "Alpha"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"hue": "Απόχρωση",
3+
"saturation": "Κορεσμού",
4+
"lightness": "Φωτεινότητα",
5+
"brightness": "Τιμή",
6+
"red": "Κόκκινο",
7+
"green": "Πράσινο",
8+
"blue": "Μπλε",
9+
"alpha": "Αλφα"
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"hue": "Hue",
3+
"saturation": "Saturation",
4+
"lightness": "Lightness",
5+
"brightness": "Brightness",
6+
"red": "Red",
7+
"green": "Green",
8+
"blue": "Blue",
9+
"alpha": "Alpha"
10+
}

0 commit comments

Comments
 (0)