@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,232 +1,188 @@
1
1
  /** @jsxImportSource @fluentui-react-native/framework-base */
2
2
  'use strict';
3
- var __createBinding =
4
- (this && this.__createBinding) ||
5
- (Object.create
6
- ? function (o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ('get' in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = {
11
- enumerable: true,
12
- get: function () {
13
- return m[k];
14
- },
15
- };
16
- }
17
- Object.defineProperty(o, k2, desc);
18
- }
19
- : function (o, m, k, k2) {
20
- if (k2 === undefined) k2 = k;
21
- o[k2] = m[k];
22
- });
23
- var __setModuleDefault =
24
- (this && this.__setModuleDefault) ||
25
- (Object.create
26
- ? function (o, v) {
27
- Object.defineProperty(o, 'default', { enumerable: true, value: v });
28
- }
29
- : function (o, v) {
30
- o['default'] = v;
31
- });
32
- var __importStar =
33
- (this && this.__importStar) ||
34
- (function () {
35
- var ownKeys = function (o) {
36
- ownKeys =
37
- Object.getOwnPropertyNames ||
38
- function (o) {
39
- var ar = [];
40
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
41
- return ar;
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
42
25
  };
43
- return ownKeys(o);
26
+ return ownKeys(o);
44
27
  };
45
28
  return function (mod) {
46
- if (mod && mod.__esModule) return mod;
47
- var result = {};
48
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== 'default') __createBinding(result, mod, k[i]);
49
- __setModuleDefault(result, mod);
50
- return result;
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
51
34
  };
52
- })();
53
- Object.defineProperty(exports, '__esModule', { value: true });
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
54
37
  exports.RadioButton = void 0;
55
- const jsx_runtime_1 = require('@fluentui-react-native/framework-base/jsx-runtime');
56
- const React = __importStar(require('react'));
57
- const react_native_1 = require('react-native');
58
- const adapters_1 = require('@fluentui-react-native/adapters');
59
- const interactive_hooks_1 = require('@fluentui-react-native/interactive-hooks');
60
- const text_1 = require('@fluentui-react-native/text');
61
- const tokens_1 = require('@fluentui-react-native/tokens');
62
- const foundation_compose_1 = require('@uifabricshared/foundation-compose');
63
- const foundation_settings_1 = require('@uifabricshared/foundation-settings');
64
- const RadioButton_settings_1 = require('./RadioButton.settings');
65
- const RadioButton_types_1 = require('./RadioButton.types');
66
- const RadioGroup_1 = require('./RadioGroup');
38
+ const jsx_runtime_1 = require("@fluentui-react-native/framework-base/jsx-runtime");
39
+ const React = __importStar(require("react"));
40
+ const react_native_1 = require("react-native");
41
+ const adapters_1 = require("@fluentui-react-native/adapters");
42
+ const interactive_hooks_1 = require("@fluentui-react-native/interactive-hooks");
43
+ const text_1 = require("@fluentui-react-native/text");
44
+ const tokens_1 = require("@fluentui-react-native/tokens");
45
+ const foundation_compose_1 = require("@uifabricshared/foundation-compose");
46
+ const foundation_settings_1 = require("@uifabricshared/foundation-settings");
47
+ const RadioButton_settings_1 = require("./RadioButton.settings");
48
+ const RadioButton_types_1 = require("./RadioButton.types");
49
+ const RadioGroup_1 = require("./RadioGroup");
67
50
  var DirectionalArrowKeys;
68
51
  (function (DirectionalArrowKeys) {
69
- DirectionalArrowKeys['ArrowUp'] = 'ArrowUp';
70
- DirectionalArrowKeys['ArrowDown'] = 'ArrowDown';
71
- DirectionalArrowKeys['ArrowRight'] = 'ArrowRight';
72
- DirectionalArrowKeys['ArrowLeft'] = 'ArrowLeft';
52
+ DirectionalArrowKeys["ArrowUp"] = "ArrowUp";
53
+ DirectionalArrowKeys["ArrowDown"] = "ArrowDown";
54
+ DirectionalArrowKeys["ArrowRight"] = "ArrowRight";
55
+ DirectionalArrowKeys["ArrowLeft"] = "ArrowLeft";
73
56
  })(DirectionalArrowKeys || (DirectionalArrowKeys = {}));
74
57
  exports.RadioButton = (0, foundation_compose_1.compose)({
75
- displayName: RadioButton_types_1.radioButtonName,
76
- usePrepareProps: (userProps, useStyling) => {
77
- const defaultComponentRef = React.useRef(null);
78
- const {
79
- content,
80
- buttonKey,
81
- disabled,
82
- accessibilityLabel,
83
- ariaLabel,
84
- componentRef = defaultComponentRef,
85
- accessibilityPosInSet,
86
- ariaPosInSet,
87
- accessibilitySetSize,
88
- ariaSetSize,
89
- ...rest
90
- } = userProps;
91
- // Grabs the context information from RadioGroup (currently selected button and client's onChange callback)
92
- const info = React.useContext(RadioGroup_1.RadioGroupContext);
93
- const buttonRef = (0, interactive_hooks_1.useViewCommandFocus)(componentRef);
94
- /* We don't want to call the user's onChange multiple times on the same selection. */
95
- const changeSelection = () => {
96
- if (buttonKey != info.selectedKey) {
97
- info.onChange && info.onChange(buttonKey);
98
- info.updateSelectedButtonRef && componentRef && info.updateSelectedButtonRef(componentRef);
99
- }
100
- };
101
- /* We use the componentRef of the currently selected button to maintain the default tabbable
58
+ displayName: RadioButton_types_1.radioButtonName,
59
+ usePrepareProps: (userProps, useStyling) => {
60
+ const defaultComponentRef = React.useRef(null);
61
+ const { content, buttonKey, disabled, accessibilityLabel, ariaLabel, componentRef = defaultComponentRef, accessibilityPosInSet, ariaPosInSet, accessibilitySetSize, ariaSetSize, ...rest } = userProps;
62
+ // Grabs the context information from RadioGroup (currently selected button and client's onChange callback)
63
+ const info = React.useContext(RadioGroup_1.RadioGroupContext);
64
+ const buttonRef = (0, interactive_hooks_1.useViewCommandFocus)(componentRef);
65
+ /* We don't want to call the user's onChange multiple times on the same selection. */
66
+ const changeSelection = () => {
67
+ if (buttonKey != info.selectedKey) {
68
+ info.onChange && info.onChange(buttonKey);
69
+ info.updateSelectedButtonRef && componentRef && info.updateSelectedButtonRef(componentRef);
70
+ }
71
+ };
72
+ /* We use the componentRef of the currently selected button to maintain the default tabbable
102
73
  element in a RadioGroup. Since the componentRef isn't generated until after initial render,
103
74
  we must update it once here. */
104
- React.useEffect(() => {
105
- if (buttonKey == info.selectedKey) {
106
- info.updateSelectedButtonRef && componentRef && info.updateSelectedButtonRef(componentRef);
107
- }
108
- }, []);
109
- // Explicitly only run on mount and unmount
110
- React.useEffect(() => {
111
- info.addRadioButtonKey(buttonKey);
112
- if (!disabled) {
113
- info.addRadioButtonEnabledKey(buttonKey);
114
- }
115
- return () => {
116
- info.removeRadioButtonKey(buttonKey);
117
- info.removeRadioButtonEnabledKey(buttonKey);
118
- };
119
- }, []);
120
- const isRTL = react_native_1.I18nManager.isRTL;
121
- const onInvoke = React.useCallback(
122
- (e) => {
123
- if (e.nativeEvent.key in DirectionalArrowKeys) {
124
- const length = info.enabledButtonKeys.length;
125
- const next =
126
- e.nativeEvent.key === DirectionalArrowKeys.ArrowDown ||
127
- (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft : e.nativeEvent.key === DirectionalArrowKeys.ArrowRight);
128
- const currRadioButtonIndex = info.enabledButtonKeys.indexOf(info.selectedKey);
129
- let newCurrRadioButtonIndex;
130
- if (next) {
131
- newCurrRadioButtonIndex = (currRadioButtonIndex + 1) % length;
132
- } else {
133
- // previous
134
- newCurrRadioButtonIndex = (currRadioButtonIndex - 1 + length) % length;
135
- }
136
- info.onChange && info.onChange(info.enabledButtonKeys[newCurrRadioButtonIndex]);
137
- info.updateInvoked && info.updateInvoked(true);
138
- }
139
- },
140
- [info],
141
- );
142
- // Sets the updated selected button ref and focus if this Radio is selected via arrow key.
143
- React.useEffect(() => {
144
- if (info.invoked && buttonKey === info.selectedKey && !disabled) {
145
- info.updateSelectedButtonRef && componentRef && info.updateSelectedButtonRef(componentRef);
146
- componentRef?.current?.focus();
147
- info.updateInvoked && info.updateInvoked(false);
148
- }
149
- }, [info.invoked]);
150
- const keys = ['ArrowDown', 'ArrowRight', 'ArrowUp', 'ArrowLeft'];
151
- // Explicitly override onKeyDown to override the native behavior of moving focus with arrow keys.
152
- const onKeyDownProps = (0, interactive_hooks_1.useKeyDownProps)(onInvoke, ...keys);
153
- // Ensure focus is placed on button after click
154
- const changeSelectionWithFocus = () => {
155
- if (buttonKey != info.selectedKey) {
156
- info.onChange && info.onChange(buttonKey);
157
- info.updateSelectedButtonRef && componentRef && info.updateSelectedButtonRef(componentRef);
158
- info.updateInvoked && info.updateInvoked(true);
159
- }
160
- };
161
- /* RadioButton changes selection when focus is moved between each RadioButton and on a click */
162
- const pressable = (0, interactive_hooks_1.useAsPressable)({
163
- ...rest,
164
- onPress: changeSelectionWithFocus,
165
- onFocus: changeSelection,
166
- });
167
- // Used when creating accessibility properties in mergeSettings below
168
- const onAccessibilityAction = React.useCallback(
169
- (event) => {
170
- switch (event.nativeEvent.actionName) {
171
- case 'Select':
172
- changeSelection();
173
- break;
174
- }
175
- },
176
- [info, buttonKey],
177
- );
178
- const state = {
179
- ...pressable.state,
180
- selected: info.selectedKey === userProps.buttonKey && !disabled,
181
- disabled: disabled || false,
182
- };
183
- // Grab the styling information from the userProps, referencing the state as well as the props.
184
- const styleProps = useStyling(userProps, (override) => state[override] || userProps[override]);
185
- const slotProps = (0, foundation_settings_1.mergeSettings)(styleProps, {
186
- root: {
187
- ...rest,
188
- ref: buttonRef,
189
- ...pressable.props,
190
- accessibilityRole: 'radio',
191
- accessibilityLabel: accessibilityLabel ?? ariaLabel ?? content,
192
- accessibilityState: { disabled: state.disabled, selected: state.selected },
193
- accessibilityActions: [{ name: 'Select', label: RadioButton_settings_1.radioButtonSelectActionLabel }],
194
- accessibilityPosInSet: accessibilityPosInSet ?? ariaPosInSet ?? info.buttonKeys.findIndex((x) => x == buttonKey) + 1,
195
- accessibilitySetSize: accessibilitySetSize ?? ariaSetSize ?? info.buttonKeys.length,
196
- focusable: !state.disabled,
197
- onAccessibilityAction: onAccessibilityAction,
198
- ...onKeyDownProps,
199
- },
200
- content: { children: content },
201
- });
202
- return { slotProps };
203
- },
204
- render: (Slots, _renderData, ...children) => {
205
- return jsx_runtime_1.jsxs(Slots.root, {
206
- children: [
207
- jsx_runtime_1.jsx(Slots.button, { children: jsx_runtime_1.jsx(Slots.innerCircle, {}) }),
208
- jsx_runtime_1.jsx(Slots.content, {}),
209
- children,
210
- ],
211
- });
212
- },
213
- settings: RadioButton_settings_1.settings,
214
- slots: {
215
- root: react_native_1.View,
216
- button: { slotType: react_native_1.View, filter: adapters_1.filterViewProps },
217
- innerCircle: { slotType: react_native_1.View, filter: adapters_1.filterViewProps },
218
- content: text_1.Text,
219
- },
220
- styles: {
221
- root: [],
222
- button: [tokens_1.borderTokens],
223
- innerCircle: [tokens_1.backgroundColorTokens],
224
- content: [
225
- tokens_1.foregroundColorTokens,
226
- tokens_1.textTokens,
227
- [{ source: 'textBorderColor', lookup: tokens_1.getPaletteFromTheme, target: 'borderColor' }],
228
- ],
229
- },
75
+ React.useEffect(() => {
76
+ if (buttonKey == info.selectedKey) {
77
+ info.updateSelectedButtonRef && componentRef && info.updateSelectedButtonRef(componentRef);
78
+ }
79
+ }, []);
80
+ // Explicitly only run on mount and unmount
81
+ React.useEffect(() => {
82
+ info.addRadioButtonKey(buttonKey);
83
+ if (!disabled) {
84
+ info.addRadioButtonEnabledKey(buttonKey);
85
+ }
86
+ return () => {
87
+ info.removeRadioButtonKey(buttonKey);
88
+ info.removeRadioButtonEnabledKey(buttonKey);
89
+ };
90
+ }, []);
91
+ const isRTL = react_native_1.I18nManager.isRTL;
92
+ const onInvoke = React.useCallback((e) => {
93
+ if (e.nativeEvent.key in DirectionalArrowKeys) {
94
+ const length = info.enabledButtonKeys.length;
95
+ const next = e.nativeEvent.key === DirectionalArrowKeys.ArrowDown ||
96
+ (isRTL ? e.nativeEvent.key === DirectionalArrowKeys.ArrowLeft : e.nativeEvent.key === DirectionalArrowKeys.ArrowRight);
97
+ const currRadioButtonIndex = info.enabledButtonKeys.indexOf(info.selectedKey);
98
+ let newCurrRadioButtonIndex;
99
+ if (next) {
100
+ newCurrRadioButtonIndex = (currRadioButtonIndex + 1) % length;
101
+ }
102
+ else {
103
+ // previous
104
+ newCurrRadioButtonIndex = (currRadioButtonIndex - 1 + length) % length;
105
+ }
106
+ info.onChange && info.onChange(info.enabledButtonKeys[newCurrRadioButtonIndex]);
107
+ info.updateInvoked && info.updateInvoked(true);
108
+ }
109
+ }, [info]);
110
+ // Sets the updated selected button ref and focus if this Radio is selected via arrow key.
111
+ React.useEffect(() => {
112
+ if (info.invoked && buttonKey === info.selectedKey && !disabled) {
113
+ info.updateSelectedButtonRef && componentRef && info.updateSelectedButtonRef(componentRef);
114
+ componentRef?.current?.focus();
115
+ info.updateInvoked && info.updateInvoked(false);
116
+ }
117
+ }, [info.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 = () => {
123
+ if (buttonKey != info.selectedKey) {
124
+ info.onChange && info.onChange(buttonKey);
125
+ info.updateSelectedButtonRef && componentRef && info.updateSelectedButtonRef(componentRef);
126
+ info.updateInvoked && info.updateInvoked(true);
127
+ }
128
+ };
129
+ /* RadioButton changes selection when focus is moved between each RadioButton and on a click */
130
+ const pressable = (0, interactive_hooks_1.useAsPressable)({
131
+ ...rest,
132
+ onPress: changeSelectionWithFocus,
133
+ onFocus: changeSelection,
134
+ });
135
+ // Used when creating accessibility properties in mergeSettings below
136
+ const onAccessibilityAction = React.useCallback((event) => {
137
+ switch (event.nativeEvent.actionName) {
138
+ case 'Select':
139
+ changeSelection();
140
+ break;
141
+ }
142
+ }, [info, buttonKey]);
143
+ const state = {
144
+ ...pressable.state,
145
+ selected: info.selectedKey === userProps.buttonKey && !disabled,
146
+ disabled: disabled || false,
147
+ };
148
+ // Grab the styling information from the userProps, referencing the state as well as the props.
149
+ const styleProps = useStyling(userProps, (override) => state[override] || userProps[override]);
150
+ const slotProps = (0, foundation_settings_1.mergeSettings)(styleProps, {
151
+ root: {
152
+ ...rest,
153
+ ref: buttonRef,
154
+ ...pressable.props,
155
+ accessibilityRole: 'radio',
156
+ accessibilityLabel: accessibilityLabel ?? ariaLabel ?? content,
157
+ accessibilityState: { disabled: state.disabled, selected: state.selected },
158
+ accessibilityActions: [{ name: 'Select', label: RadioButton_settings_1.radioButtonSelectActionLabel }],
159
+ accessibilityPosInSet: accessibilityPosInSet ?? ariaPosInSet ?? info.buttonKeys.findIndex((x) => x == buttonKey) + 1,
160
+ accessibilitySetSize: accessibilitySetSize ?? ariaSetSize ?? info.buttonKeys.length,
161
+ focusable: !state.disabled,
162
+ onAccessibilityAction: onAccessibilityAction,
163
+ ...onKeyDownProps,
164
+ },
165
+ content: { children: content },
166
+ });
167
+ return { slotProps };
168
+ },
169
+ render: (Slots, _renderData, ...children) => {
170
+ return (jsx_runtime_1.jsxs(Slots.root, { children: [
171
+ jsx_runtime_1.jsx(Slots.button, { children: jsx_runtime_1.jsx(Slots.innerCircle, {}) }), jsx_runtime_1.jsx(Slots.content, {}), children] }));
172
+ },
173
+ settings: RadioButton_settings_1.settings,
174
+ slots: {
175
+ root: react_native_1.View,
176
+ button: { slotType: react_native_1.View, filter: adapters_1.filterViewProps },
177
+ innerCircle: { slotType: react_native_1.View, filter: adapters_1.filterViewProps },
178
+ content: text_1.Text,
179
+ },
180
+ styles: {
181
+ root: [],
182
+ button: [tokens_1.borderTokens],
183
+ innerCircle: [tokens_1.backgroundColorTokens],
184
+ content: [tokens_1.foregroundColorTokens, tokens_1.textTokens, [{ source: 'textBorderColor', lookup: tokens_1.getPaletteFromTheme, target: 'borderColor' }]],
185
+ },
230
186
  });
231
187
  exports.default = exports.RadioButton;
232
- //# sourceMappingURL=RadioButton.win32.js.map
188
+ //# sourceMappingURL=RadioButton.win32.js.map
@@ -2,12 +2,6 @@
2
2
  import * as React from 'react';
3
3
  import type { IRadioGroupProps, IRadioGroupState, IRadioGroupSlotProps, IRadioGroupContext } from './RadioGroup.types';
4
4
  export declare const RadioGroupContext: React.Context<IRadioGroupContext>;
5
- export declare const RadioGroup: import('@uifabricshared/foundation-compose').IComposeReturnType<
6
- IRadioGroupProps,
7
- IRadioGroupSlotProps,
8
- import('./RadioGroup.types').IRadioGroupTokens,
9
- IRadioGroupState,
10
- object
11
- >;
5
+ export declare const RadioGroup: import("@uifabricshared/foundation-compose").IComposeReturnType<IRadioGroupProps, IRadioGroupSlotProps, import("./RadioGroup.types").IRadioGroupTokens, IRadioGroupState, object>;
12
6
  export default RadioGroup;
13
- //# sourceMappingURL=RadioGroup.d.ts.map
7
+ //# sourceMappingURL=RadioGroup.d.ts.map