@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.
- package/CHANGELOG.md +22 -0
- package/lib/Radio/Radio.d.ts +2 -7
- package/lib/Radio/Radio.ios.d.ts +2 -7
- package/lib/Radio/Radio.ios.js +31 -50
- package/lib/Radio/Radio.js +31 -46
- package/lib/Radio/Radio.styling.d.ts +1 -1
- package/lib/Radio/Radio.styling.js +88 -109
- package/lib/Radio/Radio.types.d.ts +170 -176
- package/lib/Radio/Radio.types.js +1 -1
- package/lib/Radio/RadioTokens.android.d.ts +1 -1
- package/lib/Radio/RadioTokens.android.js +42 -42
- package/lib/Radio/RadioTokens.android.js.map +1 -1
- package/lib/Radio/RadioTokens.d.ts +1 -1
- package/lib/Radio/RadioTokens.ios.d.ts +1 -1
- package/lib/Radio/RadioTokens.ios.js +39 -39
- package/lib/Radio/RadioTokens.ios.js.map +1 -1
- package/lib/Radio/RadioTokens.js +76 -76
- package/lib/Radio/RadioTokens.js.map +1 -1
- package/lib/Radio/RadioTokens.win32.d.ts +1 -1
- package/lib/Radio/RadioTokens.win32.js +89 -89
- package/lib/Radio/RadioTokens.win32.js.map +1 -1
- package/lib/Radio/__tests__/RadioExperimental.test.d.ts +1 -1
- package/lib/Radio/__tests__/RadioExperimental.test.js +14 -14
- package/lib/Radio/useRadio.d.ts +1 -1
- package/lib/Radio/useRadio.js +70 -91
- package/lib/Radio/useRadio.win32.d.ts +1 -1
- package/lib/Radio/useRadio.win32.js +121 -143
- package/lib/RadioGroup/RadioGroup.d.ts +2 -7
- package/lib/RadioGroup/RadioGroup.js +34 -48
- package/lib/RadioGroup/RadioGroup.styling.d.ts +1 -1
- package/lib/RadioGroup/RadioGroup.styling.js +42 -51
- package/lib/RadioGroup/RadioGroup.types.d.ts +117 -117
- package/lib/RadioGroup/RadioGroup.types.js +1 -1
- package/lib/RadioGroup/RadioGroupTokens.android.d.ts +1 -1
- package/lib/RadioGroup/RadioGroupTokens.android.js +1 -1
- package/lib/RadioGroup/RadioGroupTokens.d.ts +1 -1
- package/lib/RadioGroup/RadioGroupTokens.ios.d.ts +1 -1
- package/lib/RadioGroup/RadioGroupTokens.ios.js +1 -1
- package/lib/RadioGroup/RadioGroupTokens.js +12 -12
- package/lib/RadioGroup/RadioGroupTokens.js.map +1 -1
- package/lib/RadioGroup/RadioGroupTokens.mobile.d.ts +1 -1
- package/lib/RadioGroup/RadioGroupTokens.mobile.js +13 -13
- package/lib/RadioGroup/RadioGroupTokens.mobile.js.map +1 -1
- package/lib/RadioGroup/__tests__/RadioGroupExperimental.test.d.ts +1 -1
- package/lib/RadioGroup/__tests__/RadioGroupExperimental.test.js +56 -98
- package/lib/RadioGroup/radioGroupContext.d.ts +1 -1
- package/lib/RadioGroup/radioGroupContext.js +15 -19
- package/lib/RadioGroup/useRadioGroup.d.ts +1 -1
- package/lib/RadioGroup/useRadioGroup.js +63 -93
- package/lib/RadioGroup/useRadioGroupContextValue.d.ts +1 -1
- package/lib/RadioGroup/useRadioGroupContextValue.js +2 -2
- package/lib/index.d.ts +4 -25
- package/lib/index.js +1 -1
- package/lib/legacy/MacOSRadioButtonNativeComponent.d.ts +6 -6
- package/lib/legacy/MacOSRadioButtonNativeComponent.js +1 -1
- package/lib/legacy/RadioButton.d.ts +2 -8
- package/lib/legacy/RadioButton.js +80 -96
- package/lib/legacy/RadioButton.macos.d.ts +2 -8
- package/lib/legacy/RadioButton.macos.js +48 -48
- package/lib/legacy/RadioButton.settings.d.ts +2 -2
- package/lib/legacy/RadioButton.settings.js +81 -81
- package/lib/legacy/RadioButton.types.d.ts +45 -45
- package/lib/legacy/RadioButton.types.js +1 -1
- package/lib/legacy/RadioButton.win32.d.ts +2 -8
- package/lib/legacy/RadioButton.win32.js +132 -151
- package/lib/legacy/RadioGroup.d.ts +2 -8
- package/lib/legacy/RadioGroup.js +84 -108
- package/lib/legacy/RadioGroup.settings.d.ts +1 -1
- package/lib/legacy/RadioGroup.settings.js +21 -21
- package/lib/legacy/RadioGroup.types.d.ts +79 -78
- package/lib/legacy/RadioGroup.types.js +1 -1
- package/lib/legacy/__tests__/RadioButton.test.d.ts +1 -1
- package/lib/legacy/__tests__/RadioButton.test.js +8 -8
- package/lib/legacy/__tests__/RadioButtonGroup.test.d.ts +1 -1
- package/lib/legacy/__tests__/RadioButtonGroup.test.js +18 -34
- package/lib-commonjs/Radio/Radio.d.ts +2 -7
- package/lib-commonjs/Radio/Radio.ios.d.ts +2 -7
- package/lib-commonjs/Radio/Radio.ios.js +40 -64
- package/lib-commonjs/Radio/Radio.js +39 -59
- package/lib-commonjs/Radio/Radio.styling.d.ts +1 -1
- package/lib-commonjs/Radio/Radio.styling.js +94 -115
- package/lib-commonjs/Radio/Radio.types.d.ts +170 -176
- package/lib-commonjs/Radio/Radio.types.js +3 -3
- package/lib-commonjs/Radio/RadioTokens.android.d.ts +1 -1
- package/lib-commonjs/Radio/RadioTokens.android.js +45 -45
- package/lib-commonjs/Radio/RadioTokens.android.js.map +1 -1
- package/lib-commonjs/Radio/RadioTokens.d.ts +1 -1
- package/lib-commonjs/Radio/RadioTokens.ios.d.ts +1 -1
- package/lib-commonjs/Radio/RadioTokens.ios.js +42 -42
- package/lib-commonjs/Radio/RadioTokens.ios.js.map +1 -1
- package/lib-commonjs/Radio/RadioTokens.js +79 -79
- package/lib-commonjs/Radio/RadioTokens.js.map +1 -1
- package/lib-commonjs/Radio/RadioTokens.win32.d.ts +1 -1
- package/lib-commonjs/Radio/RadioTokens.win32.js +92 -92
- package/lib-commonjs/Radio/RadioTokens.win32.js.map +1 -1
- package/lib-commonjs/Radio/__tests__/RadioExperimental.test.d.ts +1 -1
- package/lib-commonjs/Radio/__tests__/RadioExperimental.test.js +48 -65
- package/lib-commonjs/Radio/useRadio.d.ts +1 -1
- package/lib-commonjs/Radio/useRadio.js +105 -143
- package/lib-commonjs/Radio/useRadio.win32.d.ts +1 -1
- package/lib-commonjs/Radio/useRadio.win32.js +157 -196
- package/lib-commonjs/RadioGroup/RadioGroup.d.ts +2 -7
- package/lib-commonjs/RadioGroup/RadioGroup.js +45 -65
- package/lib-commonjs/RadioGroup/RadioGroup.styling.d.ts +1 -1
- package/lib-commonjs/RadioGroup/RadioGroup.styling.js +48 -57
- package/lib-commonjs/RadioGroup/RadioGroup.types.d.ts +117 -117
- package/lib-commonjs/RadioGroup/RadioGroup.types.js +3 -3
- package/lib-commonjs/RadioGroup/RadioGroupTokens.android.d.ts +1 -1
- package/lib-commonjs/RadioGroup/RadioGroupTokens.android.js +5 -10
- package/lib-commonjs/RadioGroup/RadioGroupTokens.d.ts +1 -1
- package/lib-commonjs/RadioGroup/RadioGroupTokens.ios.d.ts +1 -1
- package/lib-commonjs/RadioGroup/RadioGroupTokens.ios.js +5 -10
- package/lib-commonjs/RadioGroup/RadioGroupTokens.js +15 -15
- package/lib-commonjs/RadioGroup/RadioGroupTokens.js.map +1 -1
- package/lib-commonjs/RadioGroup/RadioGroupTokens.mobile.d.ts +1 -1
- package/lib-commonjs/RadioGroup/RadioGroupTokens.mobile.js +16 -16
- package/lib-commonjs/RadioGroup/RadioGroupTokens.mobile.js.map +1 -1
- package/lib-commonjs/RadioGroup/__tests__/RadioGroupExperimental.test.d.ts +1 -1
- package/lib-commonjs/RadioGroup/__tests__/RadioGroupExperimental.test.js +91 -153
- package/lib-commonjs/RadioGroup/radioGroupContext.d.ts +1 -1
- package/lib-commonjs/RadioGroup/radioGroupContext.js +47 -68
- package/lib-commonjs/RadioGroup/useRadioGroup.d.ts +1 -1
- package/lib-commonjs/RadioGroup/useRadioGroup.js +97 -144
- package/lib-commonjs/RadioGroup/useRadioGroupContextValue.d.ts +1 -1
- package/lib-commonjs/RadioGroup/useRadioGroupContextValue.js +4 -4
- package/lib-commonjs/index.d.ts +4 -25
- package/lib-commonjs/index.js +32 -128
- package/lib-commonjs/legacy/MacOSRadioButtonNativeComponent.d.ts +6 -6
- package/lib-commonjs/legacy/MacOSRadioButtonNativeComponent.js +7 -9
- package/lib-commonjs/legacy/RadioButton.d.ts +2 -8
- package/lib-commonjs/legacy/RadioButton.js +121 -162
- package/lib-commonjs/legacy/RadioButton.macos.d.ts +2 -8
- package/lib-commonjs/legacy/RadioButton.macos.js +88 -107
- package/lib-commonjs/legacy/RadioButton.settings.d.ts +2 -2
- package/lib-commonjs/legacy/RadioButton.settings.js +84 -84
- package/lib-commonjs/legacy/RadioButton.types.d.ts +45 -45
- package/lib-commonjs/legacy/RadioButton.types.js +3 -3
- package/lib-commonjs/legacy/RadioButton.win32.d.ts +2 -8
- package/lib-commonjs/legacy/RadioButton.win32.js +173 -217
- package/lib-commonjs/legacy/RadioGroup.d.ts +2 -8
- package/lib-commonjs/legacy/RadioGroup.js +125 -168
- package/lib-commonjs/legacy/RadioGroup.settings.d.ts +1 -1
- package/lib-commonjs/legacy/RadioGroup.settings.js +24 -24
- package/lib-commonjs/legacy/RadioGroup.types.d.ts +79 -78
- package/lib-commonjs/legacy/RadioGroup.types.js +3 -3
- package/lib-commonjs/legacy/__tests__/RadioButton.test.d.ts +1 -1
- package/lib-commonjs/legacy/__tests__/RadioButton.test.js +42 -59
- package/lib-commonjs/legacy/__tests__/RadioButtonGroup.test.d.ts +1 -1
- package/lib-commonjs/legacy/__tests__/RadioButtonGroup.test.js +53 -96
- package/package.json +27 -26
- package/src/Radio/RadioTokens.android.ts +1 -1
- package/src/Radio/RadioTokens.ios.ts +1 -1
- package/src/Radio/RadioTokens.ts +1 -1
- package/src/Radio/RadioTokens.win32.ts +1 -1
- package/src/RadioGroup/RadioGroupTokens.mobile.ts +1 -1
- 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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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(
|
|
12
|
-
|
|
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
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|