) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const termsAccepted = formData.get('terms'); // 'on' when checked, null when unchecked
console.log('Terms accepted:', termsAccepted);
};
return (
);
}
```
**Custom value**
Provide a custom value that will be submitted instead of the default `'on'`:
```typescript
```
**Multiple checkboxes with the same name**
Multiple checkboxes can share the same `name` to submit an array of values:
```typescript
function MultiSelectForm() {
const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const sports = formData.getAll('sports'); // ['soccer', 'tennis'] if both checked
console.log('Selected sports:', sports);
};
return (
);
}
```
## Styling
The `Checkbox` component uses the utility function `cn` from `"@svenskaspel/ui/utils"` to concatenate default styles with any additional `className` passed as a prop. The primitive exposes `data-checked`, `data-unchecked`, `data-indeterminate`, and `data-disabled` attributes for state-based styling.