diff --git a/packages/react/src/checkbox/root/CheckboxRoot.test.tsx b/packages/react/src/checkbox/root/CheckboxRoot.test.tsx
index 3e1c8e5bc7..94098debac 100644
--- a/packages/react/src/checkbox/root/CheckboxRoot.test.tsx
+++ b/packages/react/src/checkbox/root/CheckboxRoot.test.tsx
@@ -226,11 +226,12 @@ describe('', () => {
expect(checkbox).not.to.have.attribute('data-checked');
});
- it('should set the name attribute on the input', async () => {
+ it('should set the name attribute only on the input', async () => {
const { container } = await render();
- const input = container.querySelector('input[type="checkbox"]')! as HTMLInputElement;
+ const input = container.querySelector('input[type="checkbox"]')! as HTMLInputElement;
expect(input).to.have.attribute('name', 'checkbox-name');
+ expect(screen.getByRole('checkbox')).not.to.have.attribute('name');
});
describe('Form', () => {
diff --git a/packages/react/src/switch/root/SwitchRoot.test.tsx b/packages/react/src/switch/root/SwitchRoot.test.tsx
index 9e72b2b7fb..802a4fc732 100644
--- a/packages/react/src/switch/root/SwitchRoot.test.tsx
+++ b/packages/react/src/switch/root/SwitchRoot.test.tsx
@@ -200,11 +200,14 @@ describe('', () => {
expect(thumb).not.to.have.attribute('data-checked');
});
- it('should set the name attribute on the input', async () => {
+ it('should set the name attribute only on the input', async () => {
const { getByRole } = await render();
+
+ const switchElement = screen.getByRole('switch');
const input = getByRole('checkbox', { hidden: true });
expect(input).to.have.attribute('name', 'switch-name');
+ expect(switchElement).not.to.have.attribute('name');
});
describe('Form', () => {
diff --git a/packages/react/src/switch/root/SwitchRoot.tsx b/packages/react/src/switch/root/SwitchRoot.tsx
index ebd9d3c23f..f0619e403d 100644
--- a/packages/react/src/switch/root/SwitchRoot.tsx
+++ b/packages/react/src/switch/root/SwitchRoot.tsx
@@ -36,6 +36,7 @@ export const SwitchRoot = React.forwardRef(function SwitchRoot(
defaultChecked,
id: idProp,
inputRef: externalInputRef,
+ name: nameProp,
nativeButton = true,
onCheckedChange: onCheckedChangeProp,
readOnly = false,
@@ -61,7 +62,7 @@ export const SwitchRoot = React.forwardRef(function SwitchRoot(
} = useFieldRootContext();
const disabled = fieldDisabled || disabledProp;
- const name = fieldName ?? elementProps.name;
+ const name = fieldName ?? nameProp;
const {
getValidationProps,
@@ -252,9 +253,7 @@ export const SwitchRoot = React.forwardRef(function SwitchRoot(
return (
{element}
- {!checked && elementProps.name && (
-
- )}
+ {!checked && nameProp && }
);