Skip to content

Commit bf7071f

Browse files
sookmaxreidbarberyihuiliao
authored
Add null type to Radiogroup value prop. (#5896)
* add null type to RadioGroup.props.value * add a controlled RadioGroup story --------- Co-authored-by: Reid Barber <reid@reidbarber.com> Co-authored-by: Yihui Liao <44729383+yihuiliao@users.noreply.github.com>
1 parent b5f4f6d commit bf7071f

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

packages/@react-types/radio/src/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
} from '@react-types/shared';
3030
import {ReactElement, ReactNode} from 'react';
3131

32-
export interface RadioGroupProps extends ValueBase<string>, InputBase, InputDOMProps, Validation<string | null>, LabelableProps, HelpTextProps, FocusEvents {
32+
export interface RadioGroupProps extends ValueBase<string|null, string>, InputBase, InputDOMProps, Validation<string | null>, LabelableProps, HelpTextProps, FocusEvents {
3333
/**
3434
* The axis the Radio Button(s) should align with.
3535
* @default 'vertical'

packages/react-aria-components/stories/RadioGroup.stories.tsx

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
import {Button, Dialog, DialogTrigger, Label, Modal, ModalOverlay, Radio, RadioGroup} from 'react-aria-components';
14-
import React from 'react';
14+
import React, {useState} from 'react';
1515
import styles from '../example/index.css';
1616

1717
export default {
@@ -31,6 +31,23 @@ export const RadioGroupExample = () => {
3131
);
3232
};
3333

34+
export const RadioGroupControlledExample = () => {
35+
let [selected, setSelected] = useState<string|null>(null);
36+
37+
return (
38+
<RadioGroup
39+
data-testid="radio-group-example"
40+
className={styles.radiogroup}
41+
value={selected}
42+
onChange={setSelected}>
43+
<Label>Favorite pet (controlled)</Label>
44+
<Radio className={styles.radio} value="dogs" data-testid="radio-dog">Dog</Radio>
45+
<Radio className={styles.radio} value="cats">Cat</Radio>
46+
<Radio className={styles.radio} value="dragon">Dragon</Radio>
47+
</RadioGroup>
48+
);
49+
};
50+
3451
export const RadioGroupInDialogExample = () => {
3552
return (
3653
<DialogTrigger>

0 commit comments

Comments
 (0)