stackworx / formik-mui

Bindings for using Formik with Material-UI

Home Page:https://stackworx.github.io/formik-mui

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

If no initial value is defined for `Checkbox` it does not behaves as expected

KOliver94 opened this issue · comments

Current Behavior 😯

When a Checkbox does not have a value and in an indeterminate state it changes its value to ["on"] rather than true or false for the first click then for a second click it stays selected but with value [] and you cannot change that with more clicks. If I reset the form after the second click it changes its bahavior and works as expected but the reset only solves this after the second click.

Expected Behavior 🤔

After the indeterminate state it should either be true or false for the clicks. It worked like that with MUI v4.

Steps to Reproduce 🕹

Define a Checkbox without setting its value. See the following codesandbox.

The initial value is required. Without it you will be switching from a uncontrolled to controlled component hence the warning in your codesandbox console

image

Secondly Formik has special handling for checkboxes

https://github.com/jaredpalmer/formik/blob/b9cc2536a1edb9f2d69c4cd20ecf4fa0f8059ade/packages/formik/src/Formik.tsx#L1137

The best we can do in this case if warn the user if we get an undefined value