Skip to content

Commit

Permalink
fix #11267 disabled prop not affect controller validation (#11273)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluebill1049 committed Dec 8, 2023
1 parent 4585eb3 commit a26cc94
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/__tests__/useController.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -840,4 +840,39 @@ describe('useController', () => {
screen.getByText('disable');
});
});

it('should pass validation with disabled to set to true', () => {
const callback = jest.fn();

const App = () => {
const { handleSubmit, control } = useForm({
defaultValues: {
test: 'test',
},
});
const { field } = useController({
control,
rules: {
required: true,
},
name: 'test',
disabled: true,
});

return (
<form onSubmit={handleSubmit(callback)}>
<input {...field} />
<button>submit</button>
</form>
);
};

render(<App />);

fireEvent.click(screen.getByRole('button'));

waitFor(() => {
expect(callback).toBeCalled();
});
});
});
1 change: 1 addition & 0 deletions src/useController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export function useController<
control.register(name, {
...props.rules,
value,
disabled: props.disabled,
}),
);

Expand Down

0 comments on commit a26cc94

Please sign in to comment.