Skip to content
This repository was archived by the owner on May 13, 2026. It is now read-only.

Commit f883c4f

Browse files
author
Hiromi Kimura
authored
Merge pull request #209 from xistz/feature/checkbox/value
xistz/feature/checkbox/value
2 parents d77ed3e + a469b2d commit f883c4f

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/components/Checkbox/Checkbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export type Props = {
1111
onClick?: (event: React.MouseEvent<HTMLInputElement, MouseEvent>) => void;
1212
children?: React.ReactNode;
1313
className?: string;
14-
};
14+
} & Pick<React.InputHTMLAttributes<HTMLInputElement>, 'value'>;
1515

1616
const CheckboxWrapper = styled.span`
1717
${({ theme: { checkbox } }) => css`

src/components/Checkbox/__tests__/Checkbox.test.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { render, fireEvent, screen } from '@testing-library/react';
2-
import { useState } from 'react';
2+
import userEvent from '@testing-library/user-event';
3+
import React, { useState } from 'react';
34
import { Checkbox } from '../Checkbox';
45

56
describe('Checkbox', () => {
@@ -56,4 +57,27 @@ describe('Checkbox', () => {
5657
fireEvent.click(screen.getByText('checkbox'));
5758
expect(screen.getByRole('checkbox')).toBeChecked();
5859
});
60+
61+
it('value prop', () => {
62+
const onSubmit = jest.fn();
63+
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
64+
e.preventDefault();
65+
const formData = new FormData(e.currentTarget);
66+
onSubmit(formData.get('checkbox'));
67+
};
68+
const value = 'value';
69+
render(
70+
<form onSubmit={handleSubmit}>
71+
<Checkbox value={value} name="checkbox">
72+
checkbox
73+
</Checkbox>
74+
<input type="submit" />
75+
</form>
76+
);
77+
78+
userEvent.click(screen.getByRole('checkbox', { name: 'checkbox' }));
79+
userEvent.click(screen.getByRole('button', { name: 'Submit' }));
80+
81+
expect(onSubmit).toBeCalledWith(value);
82+
});
5983
});

0 commit comments

Comments
 (0)