Checkbox when using `useTypedController` not working as expected
See original GitHub issueDescribe the bug
When using useTypedController together with a @material-ui/core
Checkbox
component, value does not change from provided default value, and is returned as string.
Codesandbox link (Required) I’ve created a Codesandbox with two checkboxes, one with default behaviour with label “Not working” and on with my fix “Working” Codesandbox
To Reproduce
- Open Codesandbox link below
- Click “save” button. Will console log default value
{ notWorking: false, working: false }
- Check “Not working” checkbox and click “save” button. Will console log default value
{ notWorking: "false", working: false }
(Remarkstring
value fornotWorking
) - Uncheck “Not working” checkbox and click “save” button. Will console log default value
{ notWorking: "false", working: false }
(Remarkstring
value fornotWorking
)
Expected behavior
The value return should be of type boolean
not string
and change to correlate to the checkbox checked state.
Solution
I’ve hijacked the onChange
event handler in render props to set event.target.value
to the value of checked
parameter, and set property checked
on Checkbox
component to value
. Working example can be seen in above Codesandbox link.
Desktop (please complete the following information):
- OS: macOS 10.15.6
- Browser Chrome
- Version 84.0.4147.89
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
no worries @FrimJo 😃 you missed something tiny there: https://codesandbox.io/s/red-framework-oj717
Thank you @bluebill1049 for clarifying ❤️
But then the docs for Strictly Typed under the Advanced section of the docs needs to be updated. There it just say to spread the props straight on to the checkbox component.