diff --git a/.changeset/form-control-reset.md b/.changeset/form-control-reset.md new file mode 100644 index 0000000000..8bc681897f --- /dev/null +++ b/.changeset/form-control-reset.md @@ -0,0 +1,9 @@ +--- +"@radix-ui/react-radio-group": patch +"@radix-ui/react-slider": patch +"@radix-ui/react-select": patch +"@radix-ui/react-switch": patch +"radix-ui": patch +--- + +All form control components now listen to their associated form's `reset` event and restore their initial value. This affects `RadioGroup`, `Slider`, `Select`, and `Switch`. diff --git a/apps/storybook/stories/radio-group.stories.tsx b/apps/storybook/stories/radio-group.stories.tsx index 9e94df5522..e03206b94a 100644 --- a/apps/storybook/stories/radio-group.stories.tsx +++ b/apps/storybook/stories/radio-group.stories.tsx @@ -90,6 +90,55 @@ export const PartsWithinForm = () => { ); }; +export const WithinFormReset = () => { + const [controlled, setControlled] = React.useState('1'); + + return ( +
event.preventDefault()}> +

+ Change the selection, then press Reset. Each group returns to its initial + value (the uncontrolled group via its defaultValue, the controlled group via + its initial value state). +

+ +
+ Uncontrolled (defaultValue) + + {['1', '2', '3'].map((value) => ( + + + + ))} + +
+ +
+
+ +
+ Controlled value: {controlled} + + {['1', '2', '3'].map((value) => ( + + + + ))} + +
+ +
+
+ + +
+ ); +}; + export const LegacyStyled = () => (