Skip to content

Commit f6ff97d

Browse files
yihuiliaodannify
andauthored
TS StrictMode for Radio (#5193)
* TS StrictMode Radio * add ts strictmode * update selectedValue type --------- Co-authored-by: Danni <darobins@adobe.com>
1 parent c424086 commit f6ff97d

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

packages/@react-spectrum/radio/src/context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ interface RadioGroupContext {
2222
export const RadioContext = React.createContext<RadioGroupContext | null>(null);
2323

2424
export function useRadioProvider(): RadioGroupContext {
25-
return useContext(RadioContext);
25+
return useContext(RadioContext) || {} as RadioGroupContext;
2626
}

packages/@react-stately/radio/src/useRadioGroupState.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface RadioGroupState {
4242
readonly isInvalid: boolean,
4343

4444
/** The currently selected value. */
45-
readonly selectedValue: string | null,
45+
readonly selectedValue: string | null | undefined,
4646

4747
/** Sets the selected value. */
4848
setSelectedValue(value: string): void,
@@ -65,7 +65,7 @@ export function useRadioGroupState(props: RadioGroupProps): RadioGroupState {
6565
// Preserved here for backward compatibility. React Aria now generates the name instead of stately.
6666
let name = useMemo(() => props.name || `radio-group-${instance}-${++i}`, [props.name]);
6767
let [selectedValue, setSelected] = useControlledState(props.value, props.defaultValue, props.onChange);
68-
let [lastFocusedValue, setLastFocusedValue] = useState(null);
68+
let [lastFocusedValue, setLastFocusedValue] = useState<string | null>(null);
6969

7070
let setSelectedValue = (value) => {
7171
if (!props.isReadOnly && !props.isDisabled) {
@@ -75,7 +75,7 @@ export function useRadioGroupState(props: RadioGroupProps): RadioGroupState {
7575

7676
return {
7777
name,
78-
selectedValue,
78+
selectedValue: selectedValue,
7979
setSelectedValue,
8080
lastFocusedValue,
8181
setLastFocusedValue,

tsconfig.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
"./packages/@react-spectrum/illustratedmessage",
4646
"./packages/@react-spectrum/image",
4747
"./packages/@react-spectrum/meter",
48+
"./packages/@react-spectrum/radio",
4849
"./packages/@react-spectrum/statuslight",
4950
"./packages/@react-spectrum/text",
5051
"./packages/@react-spectrum/view",
5152
"./packages/@react-spectrum/well",
53+
"./packages/@react-stately/radio",
5254
"./packages/@react-stately/utils",
5355
"./packages/@react-types/a",
5456
"./packages/@react-types/b",

0 commit comments

Comments
 (0)