gerhat / material-ui-formik-components

Formik ready material ui components
MIT License
85 stars 13 forks source link

Add support for textField onChange #38

Closed icrustandi closed 3 years ago

icrustandi commented 3 years ago

To resolve https://github.com/gerhat/material-ui-formik-components/issues/34

For my use case - I needed to be able to trigger a state change depending on the contents of the text field input of the autocomplete component.

This way we can just pass in the onchange to the textFieldProps within the Formik Field component:

                <Field
                    name="Some Field"
                    label="Some Field"
                    options={optionsArray || []}
                    component={Autocomplete}
                    textFieldProps={{
                        label: "Some Field",
                        onChange: (e: any) => {
                            ....onChangeHandler
                        },
                    }}
                />
gerhat commented 3 years ago

@icrustandi thank you for the PR.

Maybe the most sustainable approach is to make FAutocompleteProps interface extend AutocompleteProps from Material UI: https://github.com/mui-org/material-ui/blob/next/packages/material-ui-lab/src/Autocomplete/Autocomplete.d.ts

Tell me what you think.

icrustandi commented 3 years ago

@icrustandi thank you for the PR.

Maybe the most sustainable approach is to make FAutocompleteProps interface extend AutocompleteProps from Material UI: https://github.com/mui-org/material-ui/blob/next/packages/material-ui-lab/src/Autocomplete/Autocomplete.d.ts

Tell me what you think.

Yes! I totally agree - extending the material-ui prop type makes the most sense.

This was actually my mistake - I was using one of your old releases (0.4.1) and conflated that with your most current release. The props that I'm passing in above actually work just fine with your current release without any changes. I'm surprised there weren't any TS errors when I tried it out, but I still think it's a good idea to extend the props from material ui.

michaelpward commented 3 years ago

@gerhat Is this something that can move forward?

I'm looking to add input masks via rifm or react-input-mask. Both require a custom onChange. Seems this would help.

gerhat commented 3 years ago

@michaelpward sorry for being late on merging this. Thank you very much for your input.