diff --git a/.yarn/versions/9b826bac.yml b/.yarn/versions/9b826bac.yml new file mode 100644 index 0000000000..31ac9fbfb3 --- /dev/null +++ b/.yarn/versions/9b826bac.yml @@ -0,0 +1,5 @@ +releases: + "@radix-ui/react-switch": patch + +declined: + - primitives diff --git a/packages/react/switch/src/Switch.tsx b/packages/react/switch/src/Switch.tsx index 96ab46753c..1707674a79 100644 --- a/packages/react/switch/src/Switch.tsx +++ b/packages/react/switch/src/Switch.tsx @@ -57,44 +57,45 @@ const Switch = React.forwardRef( return ( - { - setChecked((prevChecked) => !prevChecked); - if (isFormControl) { - hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); - // if switch is in a form, stop propagation from the button so that we only propagate - // one click event (from the input). We propagate changes from an input so that native - // form validation works and form events reflect switch updates. - if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation(); - } - })} - /> - {isFormControl && ( - + { + setChecked((prevChecked) => !prevChecked); + if (isFormControl) { + hasConsumerStoppedPropagationRef.current = event.isPropagationStopped(); + // if switch is in a form, stop propagation from the button so that we only propagate + // one click event (from the input). We propagate changes from an input so that native + // form validation works and form events reflect switch updates. + if (!hasConsumerStoppedPropagationRef.current) event.stopPropagation(); + } + })} /> - )} + {isFormControl && ( + + )} + ); }