Skip to content

Commit

Permalink
Merge pull request #3736 from marmelab/fix-boolean-input
Browse files Browse the repository at this point in the history
[RFR] Fix BooleanInput Does Not Update on Label Click
  • Loading branch information
fzaninotto authored Sep 25, 2019
2 parents bb3224b + 0c05bbf commit 2bf324d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
23 changes: 22 additions & 1 deletion packages/ra-ui-materialui/src/input/BooleanInput.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React from 'react';
import { render, cleanup, fireEvent } from '@testing-library/react';
import {
render,
cleanup,
fireEvent,
waitForDomChange,
} from '@testing-library/react';
import { Form } from 'react-final-form';

import BooleanInput from './BooleanInput';
Expand Down Expand Up @@ -74,6 +79,22 @@ describe('<BooleanInput />', () => {
expect(input.checked).toBe(false);
});

it('should update on click', async () => {
const { getByLabelText } = render(
<Form
onSubmit={jest.fn}
render={() => <BooleanInput {...defaultProps} />}
/>
);

const input = getByLabelText(
'resources.posts.fields.isPublished'
) as HTMLInputElement;

fireEvent.click(input);
expect(input.checked).toBe(true);
});

it('should displays errors', () => {
// This validator always returns an error
const validate = () => 'ra.validation.error';
Expand Down
1 change: 0 additions & 1 deletion packages/ra-ui-materialui/src/input/BooleanInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const BooleanInput: FunctionComponent<
return (
<FormGroup {...sanitizeRestProps(rest)}>
<FormControlLabel
htmlFor={id}
control={
<Switch
id={id}
Expand Down

0 comments on commit 2bf324d

Please sign in to comment.