@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
@@ -1,214 +1,175 @@
1
- 'use strict';
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- var desc = Object.getOwnPropertyDescriptor(m, k);
8
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
- desc = {
10
- enumerable: true,
11
- get: function () {
12
- return m[k];
13
- },
14
- };
15
- }
16
- Object.defineProperty(o, k2, desc);
17
- }
18
- : function (o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- });
22
- var __setModuleDefault =
23
- (this && this.__setModuleDefault) ||
24
- (Object.create
25
- ? function (o, v) {
26
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
27
- }
28
- : function (o, v) {
29
- o['default'] = v;
30
- });
31
- var __importStar =
32
- (this && this.__importStar) ||
33
- (function () {
34
- var ownKeys = function (o) {
35
- ownKeys =
36
- Object.getOwnPropertyNames ||
37
- function (o) {
38
- var ar = [];
39
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
40
- return ar;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
41
24
  };
42
- return ownKeys(o);
25
+ return ownKeys(o);
43
26
  };
44
27
  return function (mod) {
45
- if (mod && mod.__esModule) return mod;
46
- var result = {};
47
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== 'default') __createBinding(result, mod, k[i]);
48
- __setModuleDefault(result, mod);
49
- return result;
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
50
33
  };
51
- })();
52
- Object.defineProperty(exports, '__esModule', { value: true });
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
53
36
  exports.useRadio = void 0;
54
- const React = __importStar(require('react'));
55
- const react_native_1 = require('react-native');
56
- const framework_1 = require('@fluentui-react-native/framework');
57
- const interactive_hooks_1 = require('@fluentui-react-native/interactive-hooks');
58
- const radioGroupContext_1 = require('../RadioGroup/radioGroupContext');
37
+ const React = __importStar(require("react"));
38
+ const react_native_1 = require("react-native");
39
+ const framework_1 = require("@fluentui-react-native/framework");
40
+ const interactive_hooks_1 = require("@fluentui-react-native/interactive-hooks");
41
+ const radioGroupContext_1 = require("../RadioGroup/radioGroupContext");
59
42
  const defaultAccessibilityActions = [{ name: 'Select' }];
60
43
  var DirectionalArrowKeys;
61
44
  (function (DirectionalArrowKeys) {
62
- DirectionalArrowKeys['ArrowUp'] = 'ArrowUp';
63
- DirectionalArrowKeys['ArrowDown'] = 'ArrowDown';
64
- DirectionalArrowKeys['ArrowRight'] = 'ArrowRight';
65
- DirectionalArrowKeys['ArrowLeft'] = 'ArrowLeft';
45
+ DirectionalArrowKeys["ArrowUp"] = "ArrowUp";
46
+ DirectionalArrowKeys["ArrowDown"] = "ArrowDown";
47
+ DirectionalArrowKeys["ArrowRight"] = "ArrowRight";
48
+ DirectionalArrowKeys["ArrowLeft"] = "ArrowLeft";
66
49
  })(DirectionalArrowKeys || (DirectionalArrowKeys = {}));
67
50
  const useRadio = (props) => {
68
- const defaultComponentRef = React.useRef(null);
69
- // Grabs the context information from RadioGroup (currently selected button and client's onChange callback)
70
- const radioGroupContext = (0, radioGroupContext_1.useRadioGroupContext)();
71
- const {
72
- label,
73
- subtext,
74
- value,
75
- disabled,
76
- accessibilityActions,
77
- accessibilityLabel,
78
- accessibilityHint,
79
- accessibilityState,
80
- componentRef = defaultComponentRef,
81
- accessibilityPosInSet,
82
- accessibilitySetSize,
83
- ...rest
84
- } = props;
85
- const labelPosition = radioGroupContext.layout === 'horizontal-stacked' ? 'below' : 'after';
86
- const isDisabled = radioGroupContext.disabled || disabled;
87
- const buttonRef = (0, interactive_hooks_1.useViewCommandFocus)(componentRef);
88
- /* We don't want to call the user's onChange multiple times on the same selection. */
89
- const changeSelection = React.useCallback(() => {
90
- if (value !== radioGroupContext.value) {
91
- radioGroupContext.onChange && radioGroupContext.onChange(value);
92
- radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
93
- }
94
- }, [radioGroupContext, value, componentRef]);
95
- /* We use the componentRef of the currently selected button to maintain the default tabbable
51
+ const defaultComponentRef = React.useRef(null);
52
+ // Grabs the context information from RadioGroup (currently selected button and client's onChange callback)
53
+ const radioGroupContext = (0, radioGroupContext_1.useRadioGroupContext)();
54
+ const { label, subtext, value, disabled, accessibilityActions, accessibilityLabel, accessibilityHint, accessibilityState, componentRef = defaultComponentRef, accessibilityPosInSet, accessibilitySetSize, ...rest } = props;
55
+ const labelPosition = radioGroupContext.layout === 'horizontal-stacked' ? 'below' : 'after';
56
+ const isDisabled = radioGroupContext.disabled || disabled;
57
+ const buttonRef = (0, interactive_hooks_1.useViewCommandFocus)(componentRef);
58
+ /* We don't want to call the user's onChange multiple times on the same selection. */
59
+ const changeSelection = React.useCallback(() => {
60
+ if (value !== radioGroupContext.value) {
61
+ radioGroupContext.onChange && radioGroupContext.onChange(value);
62
+ radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
63
+ }
64
+ }, [radioGroupContext, value, componentRef]);
65
+ /* We use the componentRef of the currently selected button to maintain the default tabbable
96
66
  element in a RadioGroup. Since the componentRef isn't generated until after initial render,
97
67
  we must update it once here. */
98
- React.useEffect(() => {
99
- if (value === radioGroupContext.value && !isDisabled) {
100
- radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
101
- }
102
- }, []);
103
- // Explicitly only run on mount and unmount
104
- React.useEffect(() => {
105
- radioGroupContext.addRadioValue(value);
106
- return () => {
107
- radioGroupContext.removeRadioValue(value);
108
- };
109
- }, []);
110
- React.useEffect(() => {
111
- if (isDisabled) {
112
- radioGroupContext.removeRadioEnabledValue(value);
113
- } else {
114
- radioGroupContext.addRadioEnabledValue(value);
115
- }
116
- }, [isDisabled]);
117
- const isRTL = react_native_1.I18nManager.isRTL;
118
- const onInvoke = React.useCallback(
119
- (e) => {
120
- if (e.nativeEvent.key in DirectionalArrowKeys) {
121
- const length = radioGroupContext.enabledValues.length;
122
- const previous =
123
- e.nativeEvent.key === DirectionalArrowKeys.ArrowUp ||
124
- (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowRight : e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft);
125
- const next =
126
- e.nativeEvent.key === DirectionalArrowKeys.ArrowDown ||
127
- (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft : e.nativeEvent.key === DirectionalArrowKeys.ArrowRight);
128
- const currRadioIndex = radioGroupContext.enabledValues.indexOf(radioGroupContext.value);
129
- let newCurrRadioIndex;
130
- if (next) {
131
- newCurrRadioIndex = (currRadioIndex + 1) % length;
132
- radioGroupContext.onChange && radioGroupContext.onChange(radioGroupContext.enabledValues[newCurrRadioIndex]);
133
- radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(true);
134
- } else if (previous) {
135
- newCurrRadioIndex = (currRadioIndex - 1 + length) % length;
136
- radioGroupContext.onChange && radioGroupContext.onChange(radioGroupContext.enabledValues[newCurrRadioIndex]);
137
- radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(true);
68
+ React.useEffect(() => {
69
+ if (value === radioGroupContext.value && !isDisabled) {
70
+ radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
138
71
  }
139
- }
140
- },
141
- [radioGroupContext],
142
- );
143
- // Sets the updated selected button ref and focus if this Radio is selected via arrow key.
144
- React.useEffect(() => {
145
- if (radioGroupContext.invoked && value === radioGroupContext.value && !isDisabled) {
146
- radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
147
- componentRef?.current?.focus();
148
- radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(false);
149
- }
150
- }, [radioGroupContext.invoked]);
151
- const keys = ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft'];
152
- // Explicitly override onKeyDown to override the native behavior of moving focus with arrow keys.
153
- const onKeyDownProps = (0, interactive_hooks_1.useKeyDownProps)(onInvoke, ...keys);
154
- // Ensure focus is placed on button after click
155
- const changeSelectionWithFocus = (0, interactive_hooks_1.useOnPressWithFocus)(componentRef, changeSelection);
156
- /* Radio changes selection when focus is moved between each RadioButton and on a click */
157
- const pressable = (0, interactive_hooks_1.usePressableState)({
158
- ...rest,
159
- onPress: changeSelectionWithFocus,
160
- onFocus: changeSelection,
161
- });
162
- const accessibilityActionsProp = React.useMemo(
163
- () => (accessibilityActions ? [...defaultAccessibilityActions, ...accessibilityActions] : defaultAccessibilityActions),
164
- [accessibilityActions],
165
- );
166
- // Used when creating accessibility properties in mergeSettings below
167
- const onAccessibilityAction = React.useCallback(
168
- (event) => {
169
- switch (event.nativeEvent.actionName) {
170
- case 'Select':
171
- changeSelection();
172
- break;
173
- }
174
- },
175
- [changeSelection],
176
- );
177
- const state = {
178
- ...pressable.state,
179
- selected: radioGroupContext.value === props.value && !isDisabled,
180
- disabled: isDisabled || false,
181
- };
182
- return {
183
- props: {
184
- value,
185
- label,
186
- subtext,
187
- labelPosition,
188
- ...rest,
189
- ref: buttonRef,
190
- ...pressable.props,
191
- accessibilityRole: 'radio',
192
- accessibilityLabel: accessibilityLabel ?? label,
193
- accessibilityHint: accessibilityHint ?? subtext,
194
- accessibilityState: getAccessibilityState(state.disabled, state.selected, accessibilityState),
195
- accessibilityActions: accessibilityActionsProp,
196
- accessibilityPosInSet: accessibilityPosInSet ?? radioGroupContext.values.findIndex((x) => x == value) + 1,
197
- accessibilitySetSize: accessibilitySetSize ?? radioGroupContext.values.length,
198
- focusable: !state.disabled,
199
- disabled: isDisabled,
200
- onAccessibilityAction: onAccessibilityAction,
201
- ...onKeyDownProps,
202
- },
203
- state: state,
204
- };
72
+ }, []);
73
+ // Explicitly only run on mount and unmount
74
+ React.useEffect(() => {
75
+ radioGroupContext.addRadioValue(value);
76
+ return () => {
77
+ radioGroupContext.removeRadioValue(value);
78
+ };
79
+ }, []);
80
+ React.useEffect(() => {
81
+ if (isDisabled) {
82
+ radioGroupContext.removeRadioEnabledValue(value);
83
+ }
84
+ else {
85
+ radioGroupContext.addRadioEnabledValue(value);
86
+ }
87
+ }, [isDisabled]);
88
+ const isRTL = react_native_1.I18nManager.isRTL;
89
+ const onInvoke = React.useCallback((e) => {
90
+ if (e.nativeEvent.key in DirectionalArrowKeys) {
91
+ const length = radioGroupContext.enabledValues.length;
92
+ const previous = e.nativeEvent.key === DirectionalArrowKeys.ArrowUp ||
93
+ (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowRight : e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft);
94
+ const next = e.nativeEvent.key === DirectionalArrowKeys.ArrowDown ||
95
+ (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft : e.nativeEvent.key === DirectionalArrowKeys.ArrowRight);
96
+ const currRadioIndex = radioGroupContext.enabledValues.indexOf(radioGroupContext.value);
97
+ let newCurrRadioIndex;
98
+ if (next) {
99
+ newCurrRadioIndex = (currRadioIndex + 1) % length;
100
+ radioGroupContext.onChange && radioGroupContext.onChange(radioGroupContext.enabledValues[newCurrRadioIndex]);
101
+ radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(true);
102
+ }
103
+ else if (previous) {
104
+ newCurrRadioIndex = (currRadioIndex - 1 + length) % length;
105
+ radioGroupContext.onChange && radioGroupContext.onChange(radioGroupContext.enabledValues[newCurrRadioIndex]);
106
+ radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(true);
107
+ }
108
+ }
109
+ }, [radioGroupContext]);
110
+ // Sets the updated selected button ref and focus if this Radio is selected via arrow key.
111
+ React.useEffect(() => {
112
+ if (radioGroupContext.invoked && value === radioGroupContext.value && !isDisabled) {
113
+ radioGroupContext.updateSelectedButtonRef && componentRef && radioGroupContext.updateSelectedButtonRef(componentRef);
114
+ componentRef?.current?.focus();
115
+ radioGroupContext.updateInvoked && radioGroupContext.updateInvoked(false);
116
+ }
117
+ }, [radioGroupContext.invoked]);
118
+ const keys = ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft'];
119
+ // Explicitly override onKeyDown to override the native behavior of moving focus with arrow keys.
120
+ const onKeyDownProps = (0, interactive_hooks_1.useKeyDownProps)(onInvoke, ...keys);
121
+ // Ensure focus is placed on button after click
122
+ const changeSelectionWithFocus = (0, interactive_hooks_1.useOnPressWithFocus)(componentRef, changeSelection);
123
+ /* Radio changes selection when focus is moved between each RadioButton and on a click */
124
+ const pressable = (0, interactive_hooks_1.usePressableState)({
125
+ ...rest,
126
+ onPress: changeSelectionWithFocus,
127
+ onFocus: changeSelection,
128
+ });
129
+ const accessibilityActionsProp = React.useMemo(() => (accessibilityActions ? [...defaultAccessibilityActions, ...accessibilityActions] : defaultAccessibilityActions), [accessibilityActions]);
130
+ // Used when creating accessibility properties in mergeSettings below
131
+ const onAccessibilityAction = React.useCallback((event) => {
132
+ switch (event.nativeEvent.actionName) {
133
+ case 'Select':
134
+ changeSelection();
135
+ break;
136
+ }
137
+ }, [changeSelection]);
138
+ const state = {
139
+ ...pressable.state,
140
+ selected: radioGroupContext.value === props.value && !isDisabled,
141
+ disabled: isDisabled || false,
142
+ };
143
+ return {
144
+ props: {
145
+ value,
146
+ label,
147
+ subtext,
148
+ labelPosition,
149
+ ...rest,
150
+ ref: buttonRef,
151
+ ...pressable.props,
152
+ accessibilityRole: 'radio',
153
+ accessibilityLabel: accessibilityLabel ?? label,
154
+ accessibilityHint: accessibilityHint ?? subtext,
155
+ accessibilityState: getAccessibilityState(state.disabled, state.selected, accessibilityState),
156
+ accessibilityActions: accessibilityActionsProp,
157
+ accessibilityPosInSet: accessibilityPosInSet ?? radioGroupContext.values.findIndex((x) => x == value) + 1,
158
+ accessibilitySetSize: accessibilitySetSize ?? radioGroupContext.values.length,
159
+ focusable: !state.disabled,
160
+ disabled: isDisabled,
161
+ onAccessibilityAction: onAccessibilityAction,
162
+ ...onKeyDownProps,
163
+ },
164
+ state: state,
165
+ };
205
166
  };
206
167
  exports.useRadio = useRadio;
207
168
  const getAccessibilityState = (0, framework_1.memoize)(getAccessibilityStateWorker);
208
169
  function getAccessibilityStateWorker(disabled, selected, accessibilityState) {
209
- if (accessibilityState) {
210
- return { disabled, selected, ...accessibilityState };
211
- }
212
- return { disabled, selected };
170
+ if (accessibilityState) {
171
+ return { disabled, selected, ...accessibilityState };
172
+ }
173
+ return { disabled, selected };
213
174
  }
214
- //# sourceMappingURL=useRadio.win32.js.map
175
+ //# 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').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").ObjectBase>;
12
+ //# sourceMappingURL=RadioGroup.d.ts.map
@@ -1,16 +1,16 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RadioGroup = exports.radioGroupLookup = void 0;
4
- const jsx_runtime_1 = require('@fluentui-react-native/framework-base/jsx-runtime');
5
- const react_native_1 = require('react-native');
6
- const focus_zone_1 = require('@fluentui-react-native/focus-zone');
7
- const framework_1 = require('@fluentui-react-native/framework');
8
- const text_1 = require('@fluentui-react-native/text');
9
- const RadioGroup_styling_1 = require('./RadioGroup.styling');
10
- const RadioGroup_types_1 = require('./RadioGroup.types');
11
- const radioGroupContext_1 = require('./radioGroupContext');
12
- const useRadioGroup_1 = require('./useRadioGroup');
13
- const useRadioGroupContextValue_1 = require('./useRadioGroupContextValue');
4
+ const jsx_runtime_1 = require("@fluentui-react-native/framework-base/jsx-runtime");
5
+ const react_native_1 = require("react-native");
6
+ const focus_zone_1 = require("@fluentui-react-native/focus-zone");
7
+ const framework_1 = require("@fluentui-react-native/framework");
8
+ const text_1 = require("@fluentui-react-native/text");
9
+ const RadioGroup_styling_1 = require("./RadioGroup.styling");
10
+ const RadioGroup_types_1 = require("./RadioGroup.types");
11
+ const radioGroupContext_1 = require("./radioGroupContext");
12
+ const useRadioGroup_1 = require("./useRadioGroup");
13
+ const useRadioGroupContextValue_1 = require("./useRadioGroupContextValue");
14
14
  /**
15
15
  * A function which determines if a set of styles should be applied to the component given the current state and props of the radiogroup.
16
16
  *
@@ -20,60 +20,40 @@ const useRadioGroupContextValue_1 = require('./useRadioGroupContextValue');
20
20
  * @returns Whether the styles that are assigned to the layer should be applied to the radiogroup
21
21
  */
22
22
  const radioGroupLookup = (layer, state, userProps) => {
23
- return (
24
- state[layer] ||
25
- userProps[layer] ||
26
- (!(react_native_1.Platform.OS === 'win32' || react_native_1.Platform.OS === 'android') &&
27
- layer === 'isHorizontal' &&
28
- (userProps['layout'] === 'horizontal' || userProps['layout'] === 'horizontal-stacked'))
29
- );
23
+ return (state[layer] ||
24
+ userProps[layer] ||
25
+ (!(react_native_1.Platform.OS === 'win32' || react_native_1.Platform.OS === 'android') &&
26
+ layer === 'isHorizontal' &&
27
+ (userProps['layout'] === 'horizontal' || userProps['layout'] === 'horizontal-stacked')));
30
28
  };
31
29
  exports.radioGroupLookup = radioGroupLookup;
32
30
  exports.RadioGroup = (0, framework_1.compose)({
33
- displayName: RadioGroup_types_1.radioGroupName,
34
- ...RadioGroup_styling_1.stylingSettings,
35
- slots: {
36
- root: react_native_1.View,
37
- label: react_native_1.View,
38
- labelText: text_1.TextV1,
39
- required: text_1.TextV1,
40
- options: react_native_1.View,
41
- container: focus_zone_1.FocusZone,
42
- },
43
- useRender: (userProps, useSlots) => {
44
- const radioGroup = (0, useRadioGroup_1.useRadioGroup)(userProps);
45
- const contextValue = (0, useRadioGroupContextValue_1.useRadioGroupContextValue)(radioGroup.state);
46
- const Slots = useSlots(userProps, (layer) => (0, exports.radioGroupLookup)(layer, radioGroup.state, userProps));
47
- return (final, ...children) => {
48
- if (!radioGroup.state) {
49
- return null;
50
- }
51
- const { label, required, defaultTabbableElement, isCircularNavigation, ...mergedProps } = (0, framework_1.mergeProps)(
52
- radioGroup.props,
53
- final,
54
- );
55
- const labelComponent = jsx_runtime_1.jsxs(Slots.label, {
56
- children: [
57
- jsx_runtime_1.jsx(Slots.labelText, { children: label }, 'label'),
58
- !!required && jsx_runtime_1.jsx(Slots.required, { children: '*' }),
59
- ],
60
- });
61
- const isFocusZoneImplemented = ['macos', 'win32'].includes(react_native_1.Platform.OS);
62
- const radioGroupContent = jsx_runtime_1.jsx(Slots.options, { children: children });
63
- const radioGroupContentWithFocusZone = jsx_runtime_1.jsx(Slots.container, {
64
- disabled: radioGroup.state.selectedButtonDisabled,
65
- isCircularNavigation: true,
66
- defaultTabbableElement: defaultTabbableElement,
67
- children: radioGroupContent,
68
- });
69
- return jsx_runtime_1.jsx(radioGroupContext_1.RadioGroupProvider, {
70
- value: contextValue,
71
- children: jsx_runtime_1.jsxs(Slots.root, {
72
- ...mergedProps,
73
- children: [label && labelComponent, isFocusZoneImplemented ? radioGroupContentWithFocusZone : radioGroupContent],
74
- }),
75
- });
76
- };
77
- },
31
+ displayName: RadioGroup_types_1.radioGroupName,
32
+ ...RadioGroup_styling_1.stylingSettings,
33
+ slots: {
34
+ root: react_native_1.View,
35
+ label: react_native_1.View,
36
+ labelText: text_1.TextV1,
37
+ required: text_1.TextV1,
38
+ options: react_native_1.View,
39
+ container: focus_zone_1.FocusZone,
40
+ },
41
+ useRender: (userProps, useSlots) => {
42
+ const radioGroup = (0, useRadioGroup_1.useRadioGroup)(userProps);
43
+ const contextValue = (0, useRadioGroupContextValue_1.useRadioGroupContextValue)(radioGroup.state);
44
+ const Slots = useSlots(userProps, (layer) => (0, exports.radioGroupLookup)(layer, radioGroup.state, userProps));
45
+ return (final, ...children) => {
46
+ if (!radioGroup.state) {
47
+ return null;
48
+ }
49
+ const { label, required, defaultTabbableElement, isCircularNavigation, ...mergedProps } = (0, framework_1.mergeProps)(radioGroup.props, final);
50
+ const labelComponent = (jsx_runtime_1.jsxs(Slots.label, { children: [
51
+ jsx_runtime_1.jsx(Slots.labelText, { children: label }, "label"), !!required && jsx_runtime_1.jsx(Slots.required, { children: '*' })] }));
52
+ const isFocusZoneImplemented = ['macos', 'win32'].includes(react_native_1.Platform.OS);
53
+ const radioGroupContent = jsx_runtime_1.jsx(Slots.options, { children: children });
54
+ const radioGroupContentWithFocusZone = (jsx_runtime_1.jsx(Slots.container, { disabled: radioGroup.state.selectedButtonDisabled, isCircularNavigation: true, defaultTabbableElement: defaultTabbableElement, children: radioGroupContent }));
55
+ return (jsx_runtime_1.jsx(radioGroupContext_1.RadioGroupProvider, { value: contextValue, children: jsx_runtime_1.jsxs(Slots.root, { ...mergedProps, children: [label && labelComponent, isFocusZoneImplemented ? radioGroupContentWithFocusZone : radioGroupContent] }) }));
56
+ };
57
+ },
78
58
  });
79
- //# sourceMappingURL=RadioGroup.js.map
59
+ //# 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
@@ -1,61 +1,52 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.stylingSettings = exports.radioGroupStates = void 0;
4
- const framework_1 = require('@fluentui-react-native/framework');
5
- const tokens_1 = require('@fluentui-react-native/tokens');
6
- const RadioGroup_types_1 = require('./RadioGroup.types');
7
- const RadioGroupTokens_1 = require('./RadioGroupTokens');
4
+ const framework_1 = require("@fluentui-react-native/framework");
5
+ const tokens_1 = require("@fluentui-react-native/tokens");
6
+ const RadioGroup_types_1 = require("./RadioGroup.types");
7
+ const RadioGroupTokens_1 = require("./RadioGroupTokens");
8
8
  exports.radioGroupStates = ['isHorizontal', 'disabled'];
9
9
  exports.stylingSettings = {
10
- tokens: [RadioGroupTokens_1.defaultRadioGroupTokens, RadioGroup_types_1.radioGroupName],
11
- states: exports.radioGroupStates,
12
- slotProps: {
13
- root: (0, framework_1.buildProps)(() => ({
14
- style: {
15
- display: 'flex',
16
- alignItems: 'flex-start',
17
- flexDirection: 'column',
18
- },
19
- })),
20
- label: (0, framework_1.buildProps)(() => ({
21
- style: {
22
- display: 'flex',
23
- alignItems: 'center',
24
- flexDirection: 'row',
25
- alignSelf: 'flex-start',
26
- },
27
- })),
28
- labelText: (0, framework_1.buildProps)(
29
- (tokens, theme) => ({
30
- variant: tokens.variant,
31
- style: {
32
- color: tokens.color,
33
- ...tokens_1.fontStyles.from(tokens, theme),
34
- },
35
- }),
36
- ['color', ...tokens_1.fontStyles.keys],
37
- ),
38
- required: (0, framework_1.buildProps)(
39
- (tokens) => ({
40
- variant: tokens.variant,
41
- style: {
42
- color: tokens.requiredColor,
43
- paddingStart: tokens.requiredPadding,
44
- },
45
- }),
46
- ['requiredColor', 'requiredPadding'],
47
- ),
48
- options: (0, framework_1.buildProps)(
49
- (tokens) => ({
50
- style: {
51
- display: 'flex',
52
- justifyContent: 'space-around',
53
- alignItems: 'flex-start',
54
- flexDirection: tokens.flexDirection,
55
- },
56
- }),
57
- ['flexDirection'],
58
- ),
59
- },
10
+ tokens: [RadioGroupTokens_1.defaultRadioGroupTokens, RadioGroup_types_1.radioGroupName],
11
+ states: exports.radioGroupStates,
12
+ slotProps: {
13
+ root: (0, framework_1.buildProps)(() => ({
14
+ style: {
15
+ display: 'flex',
16
+ alignItems: 'flex-start',
17
+ flexDirection: 'column',
18
+ },
19
+ })),
20
+ label: (0, framework_1.buildProps)(() => ({
21
+ style: {
22
+ display: 'flex',
23
+ alignItems: 'center',
24
+ flexDirection: 'row',
25
+ alignSelf: 'flex-start',
26
+ },
27
+ })),
28
+ labelText: (0, framework_1.buildProps)((tokens, theme) => ({
29
+ variant: tokens.variant,
30
+ style: {
31
+ color: tokens.color,
32
+ ...tokens_1.fontStyles.from(tokens, theme),
33
+ },
34
+ }), ['color', ...tokens_1.fontStyles.keys]),
35
+ required: (0, framework_1.buildProps)((tokens) => ({
36
+ variant: tokens.variant,
37
+ style: {
38
+ color: tokens.requiredColor,
39
+ paddingStart: tokens.requiredPadding,
40
+ },
41
+ }), ['requiredColor', 'requiredPadding']),
42
+ options: (0, framework_1.buildProps)((tokens) => ({
43
+ style: {
44
+ display: 'flex',
45
+ justifyContent: 'space-around',
46
+ alignItems: 'flex-start',
47
+ flexDirection: tokens.flexDirection,
48
+ },
49
+ }), ['flexDirection']),
50
+ },
60
51
  };
61
- //# sourceMappingURL=RadioGroup.styling.js.map
52
+ //# sourceMappingURL=RadioGroup.styling.js.map