@react-aria/color 3.0.0-beta.22 → 3.0.0-beta.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,7 +13,7 @@
13
13
  import {AriaColorAreaProps, ColorChannel} from '@react-types/color';
14
14
  import {ColorAreaState} from '@react-stately/color';
15
15
  import {DOMAttributes} from '@react-types/shared';
16
- import {focusWithoutScrolling, isAndroid, isIOS, mergeProps, useGlobalListeners, useLabels} from '@react-aria/utils';
16
+ import {focusWithoutScrolling, isAndroid, isIOS, mergeProps, useFormReset, useGlobalListeners, useLabels} from '@react-aria/utils';
17
17
  // @ts-ignore
18
18
  import intlMessages from '../intl/*.json';
19
19
  import React, {ChangeEvent, InputHTMLAttributes, RefObject, useCallback, useRef, useState} from 'react';
@@ -54,7 +54,9 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
54
54
  inputXRef,
55
55
  inputYRef,
56
56
  containerRef,
57
- 'aria-label': ariaLabel
57
+ 'aria-label': ariaLabel,
58
+ xName,
59
+ yName
58
60
  } = props;
59
61
  let stringFormatter = useLocalizedStringFormatter(intlMessages);
60
62
 
@@ -68,8 +70,15 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
68
70
  focusWithoutScrolling(inputRef.current);
69
71
  }
70
72
  }, [inputXRef]);
71
- let [valueChangedViaKeyboard, setValueChangedViaKeyboard] = useState(false);
72
73
 
74
+ useFormReset(inputXRef, [state.xValue, state.yValue], ([x, y]) => {
75
+ let newColor = state.value
76
+ .withChannelValue(state.channels.xChannel, x)
77
+ .withChannelValue(state.channels.yChannel, y);
78
+ state.setValue(newColor);
79
+ });
80
+
81
+ let [valueChangedViaKeyboard, setValueChangedViaKeyboard] = useState(false);
73
82
  let {xChannel, yChannel, zChannel} = state.channels;
74
83
  let xChannelStep = state.xChannelStep;
75
84
  let yChannelStep = state.yChannelStep;
@@ -410,6 +419,7 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
410
419
  'aria-valuetext': getAriaValueTextForChannel(xChannel),
411
420
  disabled: isDisabled,
412
421
  value: state.value.getChannelValue(xChannel),
422
+ name: xName,
413
423
  tabIndex: (isMobile || !focusedInput || focusedInput === 'x' ? undefined : -1),
414
424
  /*
415
425
  So that only a single "2d slider" control shows up when listing form elements for screen readers,
@@ -434,6 +444,7 @@ export function useColorArea(props: AriaColorAreaOptions, state: ColorAreaState)
434
444
  'aria-orientation': 'vertical',
435
445
  disabled: isDisabled,
436
446
  value: state.value.getChannelValue(yChannel),
447
+ name: yName,
437
448
  tabIndex: (isMobile || focusedInput === 'y' ? undefined : -1),
438
449
  /*
439
450
  So that only a single "2d slider" control shows up when listing form elements for screen readers,
@@ -43,7 +43,7 @@ export interface ColorSliderAria {
43
43
  * Color sliders allow users to adjust an individual channel of a color value.
44
44
  */
45
45
  export function useColorSlider(props: AriaColorSliderOptions, state: ColorSliderState): ColorSliderAria {
46
- let {trackRef, inputRef, orientation, channel, 'aria-label': ariaLabel} = props;
46
+ let {trackRef, inputRef, orientation, channel, 'aria-label': ariaLabel, name} = props;
47
47
 
48
48
  let {locale, direction} = useLocale();
49
49
 
@@ -58,6 +58,7 @@ export function useColorSlider(props: AriaColorSliderOptions, state: ColorSlider
58
58
  index: 0,
59
59
  orientation,
60
60
  isDisabled: props.isDisabled,
61
+ name,
61
62
  trackRef,
62
63
  inputRef
63
64
  }, state);
@@ -13,7 +13,7 @@
13
13
  import {AriaColorWheelProps} from '@react-types/color';
14
14
  import {ColorWheelState} from '@react-stately/color';
15
15
  import {DOMAttributes} from '@react-types/shared';
16
- import {focusWithoutScrolling, mergeProps, useGlobalListeners, useLabels} from '@react-aria/utils';
16
+ import {focusWithoutScrolling, mergeProps, useFormReset, useGlobalListeners, useLabels} from '@react-aria/utils';
17
17
  import React, {ChangeEvent, InputHTMLAttributes, RefObject, useCallback, useRef} from 'react';
18
18
  import {useKeyboard, useMove} from '@react-aria/interactions';
19
19
  import {useLocale} from '@react-aria/i18n';
@@ -43,7 +43,8 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
43
43
  isDisabled,
44
44
  innerRadius,
45
45
  outerRadius,
46
- 'aria-label': ariaLabel
46
+ 'aria-label': ariaLabel,
47
+ name
47
48
  } = props;
48
49
 
49
50
  let {addGlobalListener, removeGlobalListener} = useGlobalListeners();
@@ -56,6 +57,8 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
56
57
  }
57
58
  }, [inputRef]);
58
59
 
60
+ useFormReset(inputRef, state.hue, state.setHue);
61
+
59
62
  let currentPosition = useRef<{x: number, y: number}>(null);
60
63
 
61
64
  let {keyboardProps} = useKeyboard({
@@ -311,6 +314,7 @@ export function useColorWheel(props: AriaColorWheelOptions, state: ColorWheelSta
311
314
  'aria-valuetext': state.value.formatChannelValue('hue', locale),
312
315
  disabled: isDisabled,
313
316
  value: `${state.value.getChannelValue('hue')}`,
317
+ name,
314
318
  onChange: (e: ChangeEvent<HTMLInputElement>) => {
315
319
  state.setHue(parseFloat(e.target.value));
316
320
  }