@fluentui-react-native/radio-group 0.22.0 → 0.22.1

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.
Files changed (156) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/lib/Radio/Radio.d.ts +2 -7
  3. package/lib/Radio/Radio.ios.d.ts +2 -7
  4. package/lib/Radio/Radio.ios.js +31 -50
  5. package/lib/Radio/Radio.js +31 -46
  6. package/lib/Radio/Radio.styling.d.ts +1 -1
  7. package/lib/Radio/Radio.styling.js +88 -109
  8. package/lib/Radio/Radio.types.d.ts +170 -176
  9. package/lib/Radio/Radio.types.js +1 -1
  10. package/lib/Radio/RadioTokens.android.d.ts +1 -1
  11. package/lib/Radio/RadioTokens.android.js +42 -42
  12. package/lib/Radio/RadioTokens.android.js.map +1 -1
  13. package/lib/Radio/RadioTokens.d.ts +1 -1
  14. package/lib/Radio/RadioTokens.ios.d.ts +1 -1
  15. package/lib/Radio/RadioTokens.ios.js +39 -39
  16. package/lib/Radio/RadioTokens.ios.js.map +1 -1
  17. package/lib/Radio/RadioTokens.js +76 -76
  18. package/lib/Radio/RadioTokens.js.map +1 -1
  19. package/lib/Radio/RadioTokens.win32.d.ts +1 -1
  20. package/lib/Radio/RadioTokens.win32.js +89 -89
  21. package/lib/Radio/RadioTokens.win32.js.map +1 -1
  22. package/lib/Radio/__tests__/RadioExperimental.test.d.ts +1 -1
  23. package/lib/Radio/__tests__/RadioExperimental.test.js +14 -14
  24. package/lib/Radio/useRadio.d.ts +1 -1
  25. package/lib/Radio/useRadio.js +70 -91
  26. package/lib/Radio/useRadio.win32.d.ts +1 -1
  27. package/lib/Radio/useRadio.win32.js +121 -143
  28. package/lib/RadioGroup/RadioGroup.d.ts +2 -7
  29. package/lib/RadioGroup/RadioGroup.js +34 -48
  30. package/lib/RadioGroup/RadioGroup.styling.d.ts +1 -1
  31. package/lib/RadioGroup/RadioGroup.styling.js +42 -51
  32. package/lib/RadioGroup/RadioGroup.types.d.ts +117 -117
  33. package/lib/RadioGroup/RadioGroup.types.js +1 -1
  34. package/lib/RadioGroup/RadioGroupTokens.android.d.ts +1 -1
  35. package/lib/RadioGroup/RadioGroupTokens.android.js +1 -1
  36. package/lib/RadioGroup/RadioGroupTokens.d.ts +1 -1
  37. package/lib/RadioGroup/RadioGroupTokens.ios.d.ts +1 -1
  38. package/lib/RadioGroup/RadioGroupTokens.ios.js +1 -1
  39. package/lib/RadioGroup/RadioGroupTokens.js +12 -12
  40. package/lib/RadioGroup/RadioGroupTokens.js.map +1 -1
  41. package/lib/RadioGroup/RadioGroupTokens.mobile.d.ts +1 -1
  42. package/lib/RadioGroup/RadioGroupTokens.mobile.js +13 -13
  43. package/lib/RadioGroup/RadioGroupTokens.mobile.js.map +1 -1
  44. package/lib/RadioGroup/__tests__/RadioGroupExperimental.test.d.ts +1 -1
  45. package/lib/RadioGroup/__tests__/RadioGroupExperimental.test.js +56 -98
  46. package/lib/RadioGroup/radioGroupContext.d.ts +1 -1
  47. package/lib/RadioGroup/radioGroupContext.js +15 -19
  48. package/lib/RadioGroup/useRadioGroup.d.ts +1 -1
  49. package/lib/RadioGroup/useRadioGroup.js +63 -93
  50. package/lib/RadioGroup/useRadioGroupContextValue.d.ts +1 -1
  51. package/lib/RadioGroup/useRadioGroupContextValue.js +2 -2
  52. package/lib/index.d.ts +4 -25
  53. package/lib/index.js +1 -1
  54. package/lib/legacy/MacOSRadioButtonNativeComponent.d.ts +6 -6
  55. package/lib/legacy/MacOSRadioButtonNativeComponent.js +1 -1
  56. package/lib/legacy/RadioButton.d.ts +2 -8
  57. package/lib/legacy/RadioButton.js +80 -96
  58. package/lib/legacy/RadioButton.macos.d.ts +2 -8
  59. package/lib/legacy/RadioButton.macos.js +48 -48
  60. package/lib/legacy/RadioButton.settings.d.ts +2 -2
  61. package/lib/legacy/RadioButton.settings.js +81 -81
  62. package/lib/legacy/RadioButton.types.d.ts +45 -45
  63. package/lib/legacy/RadioButton.types.js +1 -1
  64. package/lib/legacy/RadioButton.win32.d.ts +2 -8
  65. package/lib/legacy/RadioButton.win32.js +132 -151
  66. package/lib/legacy/RadioGroup.d.ts +2 -8
  67. package/lib/legacy/RadioGroup.js +84 -108
  68. package/lib/legacy/RadioGroup.settings.d.ts +1 -1
  69. package/lib/legacy/RadioGroup.settings.js +21 -21
  70. package/lib/legacy/RadioGroup.types.d.ts +79 -78
  71. package/lib/legacy/RadioGroup.types.js +1 -1
  72. package/lib/legacy/__tests__/RadioButton.test.d.ts +1 -1
  73. package/lib/legacy/__tests__/RadioButton.test.js +8 -8
  74. package/lib/legacy/__tests__/RadioButtonGroup.test.d.ts +1 -1
  75. package/lib/legacy/__tests__/RadioButtonGroup.test.js +18 -34
  76. package/lib-commonjs/Radio/Radio.d.ts +2 -7
  77. package/lib-commonjs/Radio/Radio.ios.d.ts +2 -7
  78. package/lib-commonjs/Radio/Radio.ios.js +40 -64
  79. package/lib-commonjs/Radio/Radio.js +39 -59
  80. package/lib-commonjs/Radio/Radio.styling.d.ts +1 -1
  81. package/lib-commonjs/Radio/Radio.styling.js +94 -115
  82. package/lib-commonjs/Radio/Radio.types.d.ts +170 -176
  83. package/lib-commonjs/Radio/Radio.types.js +3 -3
  84. package/lib-commonjs/Radio/RadioTokens.android.d.ts +1 -1
  85. package/lib-commonjs/Radio/RadioTokens.android.js +45 -45
  86. package/lib-commonjs/Radio/RadioTokens.android.js.map +1 -1
  87. package/lib-commonjs/Radio/RadioTokens.d.ts +1 -1
  88. package/lib-commonjs/Radio/RadioTokens.ios.d.ts +1 -1
  89. package/lib-commonjs/Radio/RadioTokens.ios.js +42 -42
  90. package/lib-commonjs/Radio/RadioTokens.ios.js.map +1 -1
  91. package/lib-commonjs/Radio/RadioTokens.js +79 -79
  92. package/lib-commonjs/Radio/RadioTokens.js.map +1 -1
  93. package/lib-commonjs/Radio/RadioTokens.win32.d.ts +1 -1
  94. package/lib-commonjs/Radio/RadioTokens.win32.js +92 -92
  95. package/lib-commonjs/Radio/RadioTokens.win32.js.map +1 -1
  96. package/lib-commonjs/Radio/__tests__/RadioExperimental.test.d.ts +1 -1
  97. package/lib-commonjs/Radio/__tests__/RadioExperimental.test.js +48 -65
  98. package/lib-commonjs/Radio/useRadio.d.ts +1 -1
  99. package/lib-commonjs/Radio/useRadio.js +105 -143
  100. package/lib-commonjs/Radio/useRadio.win32.d.ts +1 -1
  101. package/lib-commonjs/Radio/useRadio.win32.js +157 -196
  102. package/lib-commonjs/RadioGroup/RadioGroup.d.ts +2 -7
  103. package/lib-commonjs/RadioGroup/RadioGroup.js +45 -65
  104. package/lib-commonjs/RadioGroup/RadioGroup.styling.d.ts +1 -1
  105. package/lib-commonjs/RadioGroup/RadioGroup.styling.js +48 -57
  106. package/lib-commonjs/RadioGroup/RadioGroup.types.d.ts +117 -117
  107. package/lib-commonjs/RadioGroup/RadioGroup.types.js +3 -3
  108. package/lib-commonjs/RadioGroup/RadioGroupTokens.android.d.ts +1 -1
  109. package/lib-commonjs/RadioGroup/RadioGroupTokens.android.js +5 -10
  110. package/lib-commonjs/RadioGroup/RadioGroupTokens.d.ts +1 -1
  111. package/lib-commonjs/RadioGroup/RadioGroupTokens.ios.d.ts +1 -1
  112. package/lib-commonjs/RadioGroup/RadioGroupTokens.ios.js +5 -10
  113. package/lib-commonjs/RadioGroup/RadioGroupTokens.js +15 -15
  114. package/lib-commonjs/RadioGroup/RadioGroupTokens.js.map +1 -1
  115. package/lib-commonjs/RadioGroup/RadioGroupTokens.mobile.d.ts +1 -1
  116. package/lib-commonjs/RadioGroup/RadioGroupTokens.mobile.js +16 -16
  117. package/lib-commonjs/RadioGroup/RadioGroupTokens.mobile.js.map +1 -1
  118. package/lib-commonjs/RadioGroup/__tests__/RadioGroupExperimental.test.d.ts +1 -1
  119. package/lib-commonjs/RadioGroup/__tests__/RadioGroupExperimental.test.js +91 -153
  120. package/lib-commonjs/RadioGroup/radioGroupContext.d.ts +1 -1
  121. package/lib-commonjs/RadioGroup/radioGroupContext.js +47 -68
  122. package/lib-commonjs/RadioGroup/useRadioGroup.d.ts +1 -1
  123. package/lib-commonjs/RadioGroup/useRadioGroup.js +97 -144
  124. package/lib-commonjs/RadioGroup/useRadioGroupContextValue.d.ts +1 -1
  125. package/lib-commonjs/RadioGroup/useRadioGroupContextValue.js +4 -4
  126. package/lib-commonjs/index.d.ts +4 -25
  127. package/lib-commonjs/index.js +32 -128
  128. package/lib-commonjs/legacy/MacOSRadioButtonNativeComponent.d.ts +6 -6
  129. package/lib-commonjs/legacy/MacOSRadioButtonNativeComponent.js +7 -9
  130. package/lib-commonjs/legacy/RadioButton.d.ts +2 -8
  131. package/lib-commonjs/legacy/RadioButton.js +121 -162
  132. package/lib-commonjs/legacy/RadioButton.macos.d.ts +2 -8
  133. package/lib-commonjs/legacy/RadioButton.macos.js +88 -107
  134. package/lib-commonjs/legacy/RadioButton.settings.d.ts +2 -2
  135. package/lib-commonjs/legacy/RadioButton.settings.js +84 -84
  136. package/lib-commonjs/legacy/RadioButton.types.d.ts +45 -45
  137. package/lib-commonjs/legacy/RadioButton.types.js +3 -3
  138. package/lib-commonjs/legacy/RadioButton.win32.d.ts +2 -8
  139. package/lib-commonjs/legacy/RadioButton.win32.js +173 -217
  140. package/lib-commonjs/legacy/RadioGroup.d.ts +2 -8
  141. package/lib-commonjs/legacy/RadioGroup.js +125 -168
  142. package/lib-commonjs/legacy/RadioGroup.settings.d.ts +1 -1
  143. package/lib-commonjs/legacy/RadioGroup.settings.js +24 -24
  144. package/lib-commonjs/legacy/RadioGroup.types.d.ts +79 -78
  145. package/lib-commonjs/legacy/RadioGroup.types.js +3 -3
  146. package/lib-commonjs/legacy/__tests__/RadioButton.test.d.ts +1 -1
  147. package/lib-commonjs/legacy/__tests__/RadioButton.test.js +42 -59
  148. package/lib-commonjs/legacy/__tests__/RadioButtonGroup.test.d.ts +1 -1
  149. package/lib-commonjs/legacy/__tests__/RadioButtonGroup.test.js +53 -96
  150. package/package.json +27 -26
  151. package/src/Radio/RadioTokens.android.ts +1 -1
  152. package/src/Radio/RadioTokens.ios.ts +1 -1
  153. package/src/Radio/RadioTokens.ts +1 -1
  154. package/src/Radio/RadioTokens.win32.ts +1 -1
  155. package/src/RadioGroup/RadioGroupTokens.mobile.ts +1 -1
  156. package/src/RadioGroup/RadioGroupTokens.ts +1 -1
@@ -6,155 +6,133 @@ import { useRadioGroupContext } from '../RadioGroup/radioGroupContext';
6
6
  const defaultAccessibilityActions = [{ name: 'Select' }];
7
7
  var DirectionalArrowKeys;
8
8
  (function (DirectionalArrowKeys) {
9
- DirectionalArrowKeys['ArrowUp'] = 'ArrowUp';
10
- DirectionalArrowKeys['ArrowDown'] = 'ArrowDown';
11
- DirectionalArrowKeys['ArrowRight'] = 'ArrowRight';
12
- DirectionalArrowKeys['ArrowLeft'] = 'ArrowLeft';
9
+ DirectionalArrowKeys["ArrowUp"] = "ArrowUp";
10
+ DirectionalArrowKeys["ArrowDown"] = "ArrowDown";
11
+ DirectionalArrowKeys["ArrowRight"] = "ArrowRight";
12
+ DirectionalArrowKeys["ArrowLeft"] = "ArrowLeft";
13
13
  })(DirectionalArrowKeys || (DirectionalArrowKeys = {}));
14
14
  export const useRadio = (props) => {
15
- const defaultComponentRef = React.useRef(null);
16
- // Grabs the context information from RadioGroup (currently selected button and client's onChange callback)
17
- const radioGroupContext = useRadioGroupContext();
18
- const {
19
- label,
20
- subtext,
21
- value,
22
- disabled,
23
- accessibilityActions,
24
- accessibilityLabel,
25
- accessibilityHint,
26
- accessibilityState,
27
- componentRef = defaultComponentRef,
28
- accessibilityPosInSet,
29
- accessibilitySetSize,
30
- ...rest
31
- } = props;
32
- const labelPosition = radioGroupContext.layout === 'horizontal-stacked' ? 'below' : 'after';
33
- const isDisabled = radioGroupContext.disabled || disabled;
34
- const buttonRef = useViewCommandFocus(componentRef);
35
- /* We don't want to call the user's onChange multiple times on the same selection. */
36
- const changeSelection = React.useCallback(() => {
37
- if (value !== radioGroupContext.value) {
38
- radioGroupContext.onChange && radioGroupContext.onChange(value);
39
- radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
40
- }
41
- }, [radioGroupContext, value, componentRef]);
42
- /* We use the componentRef of the currently selected button to maintain the default tabbable
15
+ const defaultComponentRef = React.useRef(null);
16
+ // Grabs the context information from RadioGroup (currently selected button and client's onChange callback)
17
+ const radioGroupContext = useRadioGroupContext();
18
+ const { label, subtext, value, disabled, accessibilityActions, accessibilityLabel, accessibilityHint, accessibilityState, componentRef = defaultComponentRef, accessibilityPosInSet, accessibilitySetSize, ...rest } = props;
19
+ const labelPosition = radioGroupContext.layout === 'horizontal-stacked' ? 'below' : 'after';
20
+ const isDisabled = radioGroupContext.disabled || disabled;
21
+ const buttonRef = useViewCommandFocus(componentRef);
22
+ /* We don't want to call the user's onChange multiple times on the same selection. */
23
+ const changeSelection = React.useCallback(() => {
24
+ if (value !== radioGroupContext.value) {
25
+ radioGroupContext.onChange && radioGroupContext.onChange(value);
26
+ radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
27
+ }
28
+ }, [radioGroupContext, value, componentRef]);
29
+ /* We use the componentRef of the currently selected button to maintain the default tabbable
43
30
  element in a RadioGroup. Since the componentRef isn't generated until after initial render,
44
31
  we must update it once here. */
45
- React.useEffect(() => {
46
- if (value === radioGroupContext.value && !isDisabled) {
47
- radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
48
- }
49
- }, []);
50
- // Explicitly only run on mount and unmount
51
- React.useEffect(() => {
52
- radioGroupContext.addRadioValue(value);
53
- return () => {
54
- radioGroupContext.removeRadioValue(value);
55
- };
56
- }, []);
57
- React.useEffect(() => {
58
- if (isDisabled) {
59
- radioGroupContext.removeRadioEnabledValue(value);
60
- } else {
61
- radioGroupContext.addRadioEnabledValue(value);
62
- }
63
- }, [isDisabled]);
64
- const isRTL = I18nManager.isRTL;
65
- const onInvoke = React.useCallback(
66
- (e) => {
67
- if (e.nativeEvent.key in DirectionalArrowKeys) {
68
- const length = radioGroupContext.enabledValues.length;
69
- const previous =
70
- e.nativeEvent.key === DirectionalArrowKeys.ArrowUp ||
71
- (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowRight : e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft);
72
- const next =
73
- e.nativeEvent.key === DirectionalArrowKeys.ArrowDown ||
74
- (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft : e.nativeEvent.key === DirectionalArrowKeys.ArrowRight);
75
- const currRadioIndex = radioGroupContext.enabledValues.indexOf(radioGroupContext.value);
76
- let newCurrRadioIndex;
77
- if (next) {
78
- newCurrRadioIndex = (currRadioIndex + 1) % length;
79
- radioGroupContext.onChange && radioGroupContext.onChange(radioGroupContext.enabledValues[newCurrRadioIndex]);
80
- radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(true);
81
- } else if (previous) {
82
- newCurrRadioIndex = (currRadioIndex - 1 + length) % length;
83
- radioGroupContext.onChange && radioGroupContext.onChange(radioGroupContext.enabledValues[newCurrRadioIndex]);
84
- radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(true);
32
+ React.useEffect(() => {
33
+ if (value === radioGroupContext.value && !isDisabled) {
34
+ radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
85
35
  }
86
- }
87
- },
88
- [radioGroupContext],
89
- );
90
- // Sets the updated selected button ref and focus if this Radio is selected via arrow key.
91
- React.useEffect(() => {
92
- if (radioGroupContext.invoked && value === radioGroupContext.value && !isDisabled) {
93
- radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
94
- componentRef?.current?.focus();
95
- radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(false);
96
- }
97
- }, [radioGroupContext.invoked]);
98
- const keys = ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft'];
99
- // Explicitly override onKeyDown to override the native behavior of moving focus with arrow keys.
100
- const onKeyDownProps = useKeyDownProps(onInvoke, ...keys);
101
- // Ensure focus is placed on button after click
102
- const changeSelectionWithFocus = useOnPressWithFocus(componentRef, changeSelection);
103
- /* Radio changes selection when focus is moved between each RadioButton and on a click */
104
- const pressable = usePressableState({
105
- ...rest,
106
- onPress: changeSelectionWithFocus,
107
- onFocus: changeSelection,
108
- });
109
- const accessibilityActionsProp = React.useMemo(
110
- () => (accessibilityActions ? [...defaultAccessibilityActions, ...accessibilityActions] : defaultAccessibilityActions),
111
- [accessibilityActions],
112
- );
113
- // Used when creating accessibility properties in mergeSettings below
114
- const onAccessibilityAction = React.useCallback(
115
- (event) => {
116
- switch (event.nativeEvent.actionName) {
117
- case 'Select':
118
- changeSelection();
119
- break;
120
- }
121
- },
122
- [changeSelection],
123
- );
124
- const state = {
125
- ...pressable.state,
126
- selected: radioGroupContext.value === props.value && !isDisabled,
127
- disabled: isDisabled || false,
128
- };
129
- return {
130
- props: {
131
- value,
132
- label,
133
- subtext,
134
- labelPosition,
135
- ...rest,
136
- ref: buttonRef,
137
- ...pressable.props,
138
- accessibilityRole: 'radio',
139
- accessibilityLabel: accessibilityLabel ?? label,
140
- accessibilityHint: accessibilityHint ?? subtext,
141
- accessibilityState: getAccessibilityState(state.disabled, state.selected, accessibilityState),
142
- accessibilityActions: accessibilityActionsProp,
143
- accessibilityPosInSet: accessibilityPosInSet ?? radioGroupContext.values.findIndex((x) => x == value) + 1,
144
- accessibilitySetSize: accessibilitySetSize ?? radioGroupContext.values.length,
145
- focusable: !state.disabled,
146
- disabled: isDisabled,
147
- onAccessibilityAction: onAccessibilityAction,
148
- ...onKeyDownProps,
149
- },
150
- state: state,
151
- };
36
+ }, []);
37
+ // Explicitly only run on mount and unmount
38
+ React.useEffect(() => {
39
+ radioGroupContext.addRadioValue(value);
40
+ return () => {
41
+ radioGroupContext.removeRadioValue(value);
42
+ };
43
+ }, []);
44
+ React.useEffect(() => {
45
+ if (isDisabled) {
46
+ radioGroupContext.removeRadioEnabledValue(value);
47
+ }
48
+ else {
49
+ radioGroupContext.addRadioEnabledValue(value);
50
+ }
51
+ }, [isDisabled]);
52
+ const isRTL = I18nManager.isRTL;
53
+ const onInvoke = React.useCallback((e) => {
54
+ if (e.nativeEvent.key in DirectionalArrowKeys) {
55
+ const length = radioGroupContext.enabledValues.length;
56
+ const previous = e.nativeEvent.key === DirectionalArrowKeys.ArrowUp ||
57
+ (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowRight : e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft);
58
+ const next = e.nativeEvent.key === DirectionalArrowKeys.ArrowDown ||
59
+ (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft : e.nativeEvent.key === DirectionalArrowKeys.ArrowRight);
60
+ const currRadioIndex = radioGroupContext.enabledValues.indexOf(radioGroupContext.value);
61
+ let newCurrRadioIndex;
62
+ if (next) {
63
+ newCurrRadioIndex = (currRadioIndex + 1) % length;
64
+ radioGroupContext.onChange && radioGroupContext.onChange(radioGroupContext.enabledValues[newCurrRadioIndex]);
65
+ radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(true);
66
+ }
67
+ else if (previous) {
68
+ newCurrRadioIndex = (currRadioIndex - 1 + length) % length;
69
+ radioGroupContext.onChange && radioGroupContext.onChange(radioGroupContext.enabledValues[newCurrRadioIndex]);
70
+ radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(true);
71
+ }
72
+ }
73
+ }, [radioGroupContext]);
74
+ // Sets the updated selected button ref and focus if this Radio is selected via arrow key.
75
+ React.useEffect(() => {
76
+ if (radioGroupContext.invoked && value === radioGroupContext.value && !isDisabled) {
77
+ radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
78
+ componentRef?.current?.focus();
79
+ radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(false);
80
+ }
81
+ }, [radioGroupContext.invoked]);
82
+ const keys = ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft'];
83
+ // Explicitly override onKeyDown to override the native behavior of moving focus with arrow keys.
84
+ const onKeyDownProps = useKeyDownProps(onInvoke, ...keys);
85
+ // Ensure focus is placed on button after click
86
+ const changeSelectionWithFocus = useOnPressWithFocus(componentRef, changeSelection);
87
+ /* Radio changes selection when focus is moved between each RadioButton and on a click */
88
+ const pressable = usePressableState({
89
+ ...rest,
90
+ onPress: changeSelectionWithFocus,
91
+ onFocus: changeSelection,
92
+ });
93
+ const accessibilityActionsProp = React.useMemo(() => (accessibilityActions ? [...defaultAccessibilityActions, ...accessibilityActions] : defaultAccessibilityActions), [accessibilityActions]);
94
+ // Used when creating accessibility properties in mergeSettings below
95
+ const onAccessibilityAction = React.useCallback((event) => {
96
+ switch (event.nativeEvent.actionName) {
97
+ case 'Select':
98
+ changeSelection();
99
+ break;
100
+ }
101
+ }, [changeSelection]);
102
+ const state = {
103
+ ...pressable.state,
104
+ selected: radioGroupContext.value === props.value && !isDisabled,
105
+ disabled: isDisabled || false,
106
+ };
107
+ return {
108
+ props: {
109
+ value,
110
+ label,
111
+ subtext,
112
+ labelPosition,
113
+ ...rest,
114
+ ref: buttonRef,
115
+ ...pressable.props,
116
+ accessibilityRole: 'radio',
117
+ accessibilityLabel: accessibilityLabel ?? label,
118
+ accessibilityHint: accessibilityHint ?? subtext,
119
+ accessibilityState: getAccessibilityState(state.disabled, state.selected, accessibilityState),
120
+ accessibilityActions: accessibilityActionsProp,
121
+ accessibilityPosInSet: accessibilityPosInSet ?? radioGroupContext.values.findIndex((x) => x == value) + 1,
122
+ accessibilitySetSize: accessibilitySetSize ?? radioGroupContext.values.length,
123
+ focusable: !state.disabled,
124
+ disabled: isDisabled,
125
+ onAccessibilityAction: onAccessibilityAction,
126
+ ...onKeyDownProps,
127
+ },
128
+ state: state,
129
+ };
152
130
  };
153
131
  const getAccessibilityState = memoize(getAccessibilityStateWorker);
154
132
  function getAccessibilityStateWorker(disabled, selected, accessibilityState) {
155
- if (accessibilityState) {
156
- return { disabled, selected, ...accessibilityState };
157
- }
158
- return { disabled, selected };
133
+ if (accessibilityState) {
134
+ return { disabled, selected, ...accessibilityState };
135
+ }
136
+ return { disabled, selected };
159
137
  }
160
- //# sourceMappingURL=useRadio.win32.js.map
138
+ //# sourceMappingURL=useRadio.win32.js.map
@@ -8,10 +8,5 @@ import type { RadioGroupProps, RadioGroupState } from './RadioGroup.types';
8
8
  * @returns Whether the styles that are assigned to the layer should be applied to the radiogroup
9
9
  */
10
10
  export declare const radioGroupLookup: (layer: string, state: RadioGroupState, userProps: RadioGroupProps) => boolean;
11
- export declare const RadioGroup: import('@fluentui-react-native/framework').ComposableComponent<
12
- RadioGroupProps,
13
- import('./RadioGroup.types').RadioGroupSlotProps,
14
- import('./RadioGroup.types').RadioGroupTokens,
15
- import('@fluentui-react-native/framework-base').ObjectBase
16
- >;
17
- //# sourceMappingURL=RadioGroup.d.ts.map
11
+ export declare const RadioGroup: import("@fluentui-react-native/framework").ComposableComponent<RadioGroupProps, import("./RadioGroup.types").RadioGroupSlotProps, import("./RadioGroup.types").RadioGroupTokens, import("@fluentui-react-native/framework-base").ObjectBase>;
12
+ //# sourceMappingURL=RadioGroup.d.ts.map
@@ -1,4 +1,4 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from '@fluentui-react-native/framework-base/jsx-runtime';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "@fluentui-react-native/framework-base/jsx-runtime";
2
2
  import { Platform, View } from 'react-native';
3
3
  import { FocusZone } from '@fluentui-react-native/focus-zone';
4
4
  import { compose, mergeProps } from '@fluentui-react-native/framework';
@@ -17,53 +17,39 @@ import { useRadioGroupContextValue } from './useRadioGroupContextValue';
17
17
  * @returns Whether the styles that are assigned to the layer should be applied to the radiogroup
18
18
  */
19
19
  export const radioGroupLookup = (layer, state, userProps) => {
20
- return (
21
- state[layer] ||
22
- userProps[layer] ||
23
- (!(Platform.OS === 'win32' || Platform.OS === 'android') &&
24
- layer === 'isHorizontal' &&
25
- (userProps['layout'] === 'horizontal' || userProps['layout'] === 'horizontal-stacked'))
26
- );
20
+ return (state[layer] ||
21
+ userProps[layer] ||
22
+ (!(Platform.OS === 'win32' || Platform.OS === 'android') &&
23
+ layer === 'isHorizontal' &&
24
+ (userProps['layout'] === 'horizontal' || userProps['layout'] === 'horizontal-stacked')));
27
25
  };
28
26
  export const RadioGroup = compose({
29
- displayName: radioGroupName,
30
- ...stylingSettings,
31
- slots: {
32
- root: View,
33
- label: View,
34
- labelText: Text,
35
- required: Text,
36
- options: View,
37
- container: FocusZone,
38
- },
39
- useRender: (userProps, useSlots) => {
40
- const radioGroup = useRadioGroup(userProps);
41
- const contextValue = useRadioGroupContextValue(radioGroup.state);
42
- const Slots = useSlots(userProps, (layer) => radioGroupLookup(layer, radioGroup.state, userProps));
43
- return (final, ...children) => {
44
- if (!radioGroup.state) {
45
- return null;
46
- }
47
- const { label, required, defaultTabbableElement, isCircularNavigation, ...mergedProps } = mergeProps(radioGroup.props, final);
48
- const labelComponent = _jsxs(Slots.label, {
49
- children: [_jsx(Slots.labelText, { children: label }, 'label'), !!required && _jsx(Slots.required, { children: '*' })],
50
- });
51
- const isFocusZoneImplemented = ['macos', 'win32'].includes(Platform.OS);
52
- const radioGroupContent = _jsx(Slots.options, { children: children });
53
- const radioGroupContentWithFocusZone = _jsx(Slots.container, {
54
- disabled: radioGroup.state.selectedButtonDisabled,
55
- isCircularNavigation: true,
56
- defaultTabbableElement: defaultTabbableElement,
57
- children: radioGroupContent,
58
- });
59
- return _jsx(RadioGroupProvider, {
60
- value: contextValue,
61
- children: _jsxs(Slots.root, {
62
- ...mergedProps,
63
- children: [label && labelComponent, isFocusZoneImplemented ? radioGroupContentWithFocusZone : radioGroupContent],
64
- }),
65
- });
66
- };
67
- },
27
+ displayName: radioGroupName,
28
+ ...stylingSettings,
29
+ slots: {
30
+ root: View,
31
+ label: View,
32
+ labelText: Text,
33
+ required: Text,
34
+ options: View,
35
+ container: FocusZone,
36
+ },
37
+ useRender: (userProps, useSlots) => {
38
+ const radioGroup = useRadioGroup(userProps);
39
+ const contextValue = useRadioGroupContextValue(radioGroup.state);
40
+ const Slots = useSlots(userProps, (layer) => radioGroupLookup(layer, radioGroup.state, userProps));
41
+ return (final, ...children) => {
42
+ if (!radioGroup.state) {
43
+ return null;
44
+ }
45
+ const { label, required, defaultTabbableElement, isCircularNavigation, ...mergedProps } = mergeProps(radioGroup.props, final);
46
+ const labelComponent = (_jsxs(Slots.label, { children: [
47
+ _jsx(Slots.labelText, { children: label }, "label"), !!required && _jsx(Slots.required, { children: '*' })] }));
48
+ const isFocusZoneImplemented = ['macos', 'win32'].includes(Platform.OS);
49
+ const radioGroupContent = _jsx(Slots.options, { children: children });
50
+ const radioGroupContentWithFocusZone = (_jsx(Slots.container, { disabled: radioGroup.state.selectedButtonDisabled, isCircularNavigation: true, defaultTabbableElement: defaultTabbableElement, children: radioGroupContent }));
51
+ return (_jsx(RadioGroupProvider, { value: contextValue, children: _jsxs(Slots.root, { ...mergedProps, children: [label && labelComponent, isFocusZoneImplemented ? radioGroupContentWithFocusZone : radioGroupContent] }) }));
52
+ };
53
+ },
68
54
  });
69
- //# sourceMappingURL=RadioGroup.js.map
55
+ //# sourceMappingURL=RadioGroup.js.map
@@ -2,4 +2,4 @@ import type { UseStylingOptions } from '@fluentui-react-native/framework';
2
2
  import type { RadioGroupTokens, RadioGroupSlotProps, RadioGroupProps } from './RadioGroup.types';
3
3
  export declare const radioGroupStates: (keyof RadioGroupTokens)[];
4
4
  export declare const stylingSettings: UseStylingOptions<RadioGroupProps, RadioGroupSlotProps, RadioGroupTokens>;
5
- //# sourceMappingURL=RadioGroup.styling.d.ts.map
5
+ //# sourceMappingURL=RadioGroup.styling.d.ts.map
@@ -4,55 +4,46 @@ import { radioGroupName } from './RadioGroup.types';
4
4
  import { defaultRadioGroupTokens } from './RadioGroupTokens';
5
5
  export const radioGroupStates = ['isHorizontal', 'disabled'];
6
6
  export const stylingSettings = {
7
- tokens: [defaultRadioGroupTokens, radioGroupName],
8
- states: radioGroupStates,
9
- slotProps: {
10
- root: buildProps(() => ({
11
- style: {
12
- display: 'flex',
13
- alignItems: 'flex-start',
14
- flexDirection: 'column',
15
- },
16
- })),
17
- label: buildProps(() => ({
18
- style: {
19
- display: 'flex',
20
- alignItems: 'center',
21
- flexDirection: 'row',
22
- alignSelf: 'flex-start',
23
- },
24
- })),
25
- labelText: buildProps(
26
- (tokens, theme) => ({
27
- variant: tokens.variant,
28
- style: {
29
- color: tokens.color,
30
- ...fontStyles.from(tokens, theme),
31
- },
32
- }),
33
- ['color', ...fontStyles.keys],
34
- ),
35
- required: buildProps(
36
- (tokens) => ({
37
- variant: tokens.variant,
38
- style: {
39
- color: tokens.requiredColor,
40
- paddingStart: tokens.requiredPadding,
41
- },
42
- }),
43
- ['requiredColor', 'requiredPadding'],
44
- ),
45
- options: buildProps(
46
- (tokens) => ({
47
- style: {
48
- display: 'flex',
49
- justifyContent: 'space-around',
50
- alignItems: 'flex-start',
51
- flexDirection: tokens.flexDirection,
52
- },
53
- }),
54
- ['flexDirection'],
55
- ),
56
- },
7
+ tokens: [defaultRadioGroupTokens, radioGroupName],
8
+ states: radioGroupStates,
9
+ slotProps: {
10
+ root: buildProps(() => ({
11
+ style: {
12
+ display: 'flex',
13
+ alignItems: 'flex-start',
14
+ flexDirection: 'column',
15
+ },
16
+ })),
17
+ label: buildProps(() => ({
18
+ style: {
19
+ display: 'flex',
20
+ alignItems: 'center',
21
+ flexDirection: 'row',
22
+ alignSelf: 'flex-start',
23
+ },
24
+ })),
25
+ labelText: buildProps((tokens, theme) => ({
26
+ variant: tokens.variant,
27
+ style: {
28
+ color: tokens.color,
29
+ ...fontStyles.from(tokens, theme),
30
+ },
31
+ }), ['color', ...fontStyles.keys]),
32
+ required: buildProps((tokens) => ({
33
+ variant: tokens.variant,
34
+ style: {
35
+ color: tokens.requiredColor,
36
+ paddingStart: tokens.requiredPadding,
37
+ },
38
+ }), ['requiredColor', 'requiredPadding']),
39
+ options: buildProps((tokens) => ({
40
+ style: {
41
+ display: 'flex',
42
+ justifyContent: 'space-around',
43
+ alignItems: 'flex-start',
44
+ flexDirection: tokens.flexDirection,
45
+ },
46
+ }), ['flexDirection']),
47
+ },
57
48
  };
58
- //# sourceMappingURL=RadioGroup.styling.js.map
49
+ //# sourceMappingURL=RadioGroup.styling.js.map