Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/react-aria-components/src/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {FormContext} from './Form';
import {forwardRefType, RefObject} from '@react-types/shared';
import {LabelContext} from './Label';
import {RadioGroupState, useRadioGroupState} from 'react-stately';
import React, {createContext, ForwardedRef, forwardRef} from 'react';
import React, {createContext, ForwardedRef, forwardRef, useMemo} from 'react';
import {TextContext} from './Text';

export interface RadioGroupProps extends Omit<AriaRadioGroupProps, 'children' | 'label' | 'description' | 'errorMessage' | 'validationState' | 'validationBehavior'>, RACValidation, RenderProps<RadioGroupRenderProps>, SlotProps {}
Expand Down Expand Up @@ -186,7 +186,7 @@ export const Radio = /*#__PURE__*/ (forwardRef as forwardRefType)(function Radio
} = props;
[props, ref] = useContextProps(otherProps, ref, RadioContext);
let state = React.useContext(RadioGroupStateContext)!;
let inputRef = useObjectRef(mergeRefs(userProvidedInputRef, props.inputRef !== undefined ? props.inputRef : null));
let inputRef = useObjectRef(useMemo(() => mergeRefs(userProvidedInputRef, props.inputRef !== undefined ? props.inputRef : null), [userProvidedInputRef, props.inputRef]));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is correct, we usually useMemo with mergeRefs and useObjectRef, it looks like this one was missed

let {labelProps, inputProps, isSelected, isDisabled, isPressed} = useRadio({
...removeDataAttributes<RadioProps>(props),
// ReactNode type doesn't allow function children.
Expand Down
21 changes: 20 additions & 1 deletion packages/react-aria-components/stories/RadioGroup.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* governing permissions and limitations under the License.
*/

import {Button, Dialog, DialogTrigger, Label, Modal, ModalOverlay, Radio, RadioGroup} from 'react-aria-components';
import {Button, Dialog, DialogTrigger, FieldError, Form, Label, Modal, ModalOverlay, Radio, RadioGroup} from 'react-aria-components';
import React, {useState} from 'react';
import styles from '../example/index.css';

Expand Down Expand Up @@ -96,3 +96,22 @@ export const RadioGroupInDialogExample = () => {
</DialogTrigger>
);
};

export const RadioGroupSubmitExample = () => {
return (
<Form>
<RadioGroup
className={styles.radiogroup}
data-testid="radio-group-example"
isRequired>
<Label>Favorite pet</Label>
<Radio className={styles.radio} value="dogs" data-testid="radio-dog">Dog</Radio>
<Radio className={styles.radio} value="cats">Cat</Radio>
<Radio className={styles.radio} value="dragon">Dragon</Radio>
<FieldError className={styles.errorMessage} />
</RadioGroup>
<Button type="submit">Submit</Button>
<Button type="reset">Reset</Button>
</Form>
);
};