GithubHelp home page GithubHelp logo

dohomi / react-hook-form-mui Goto Github PK

View Code? Open in Web Editor NEW
533.0 10.0 108.0 53.88 MB

Material-UI form components ready to use with react-hook-form

Home Page: https://react-hook-form-material-ui.vercel.app

License: MIT License

JavaScript 98.40% TypeScript 1.30% HTML 0.30% CSS 0.01%
material-ui react-hook-form react typescript

react-hook-form-mui's Introduction

Material-UI and react-hook-form combined

GitHub Average time to resolve an issue Percentage of issues still open

About this project

This project simplifies the use of react-hook-form and Material-UI. It provides opinionated use cases with following components:

  • FormContainer
  • AutocompleteElement
  • TextFieldElement
  • SelectElement
  • MultiSelectElement
  • RadioButtonGroup
  • CheckboxButtonGroup
  • CheckboxElement
  • SwitchElement
  • PasswordElement
  • DatePickerElement
  • DateTimePickerElement
  • SliderElement
  • ToggleButtonGroupElement

Please check out the demo for the element overview.

How to use it

Installation

# npm install react-hook-form react-hook-form-mui
# yarn add react-hook-form react-hook-form-mui

This package utilizes pickers and icons of the MUI ecosystem. If you make use of it add them to your app.

#  npm install @mui/x-date-pickers @mui/icons-material
#  yarn add @mui/x-date-pickers @mui/icons-material

Important

From versions >= 3.x of this package MUI v5 is in use. Versions of 1 & 2 using Material-UI v4

From version >= 6 x-date-pickers version 6 is in use. Make sure you upgrade your dependencies.

Simple form setup

import {FormContainer, TextFieldElement} from 'react-hook-form-mui'

function Form() {
    return (
        <FormContainer
            defaultValues={{name: ''}}
            onSuccess={data => console.log(data)}
        >
            <TextFieldElement name="name" label="Name" required/>
        </FormContainer>
    )
}

Typesafe form setup

  function Form() {
    const {control, handleSubmit} = useForm({
      defaultValues: {
        name: '',
        auto: '',
        check: false
      },
    })
    const options = [
      {id: 'one', label: 'One'},
      {id: 'two', label: 'Two'},
      {id: 'three', label: 'Three'},
    ]
    return (
        <form onSubmit={handleSubmit((data) => console.log(data))} noValidate>
          <Stack spacing={2}>
            <TextFieldElement
              name={'name'}
              label={'Name'}
              control={control}
              required
              fullWidth
            />
            <AutocompleteElement
              name={'auto'}
              label={'Autocomplete'}
              control={control}
              options={options}
            />
            <CheckboxElement name={'check'} label={'Check'} control={control} />
            <Button type={'submit'} color={'primary'}>
              Submit
            </Button>
          </Stack>
        </form>
    )
  }

You can have a look at all different possibilities to use forms at following code examples

FormContainer creates formContext

The <FormContainer /> wires up a form and you can create sub-components which either make use of useFormContext() | useWatch() to react to form values.

Demo

Check out Storybook: Demo

You will find examples and use cases.

With Datepicker

If you are using the DatepickerElement keep in mind that you have to wrap your form with a provider:

Examples for Dayjs or DateFns provider (used in the demo):

Troubleshooting

Issues if context is undefined (useWatch)

For convenient reasons this package is re-exporting react-hook-form which is especially required if you have context issues of React.

import {useWatch} from 'react-hook-form-mui' // instead of react-hook-form

const MySubmit = () => {
    const value = useWatch('fieldName')
    return (
        <Button disabled={!value}>Submit</Button>
    )
}

Bundle

This project uses tsup to wrap the package for npm.

Support Maintanance

If you find this package useful consider a small contribution: Buy Me A Coffee

Contributing

Make sure you're running Node.js 20

  1. Clone this repository
git clone https://github.com/dohomi/react-hook-form-mui.git
cd react-hook-form-mui
  1. Install dependencies
yarn
  1. Build the project
yarn build
  1. Run the storybook
yarn sb-start

Changes to storybook stories can be made in apps/storybook/stories. Changes to the library can be made in packages/rhf-mui.

react-hook-form-mui's People

Contributors

bethmaloney avatar beverloo avatar dependabot[bot] avatar dohomi avatar dzej1 avatar fdiskas avatar homig avatar jacokok avatar johnmoxley avatar jsun969 avatar korstan avatar mashabow avatar maskedhawk avatar mg-chao avatar morriz avatar mwarger avatar nicholasmata avatar panudetjt avatar patrollings avatar rafaelsteil avatar rclankhorst avatar sadik-malik avatar shkreios avatar tchell avatar timmikeladze avatar tkaczykadam avatar tomfreudenberg avatar valerii15298 avatar waza-ari avatar yasamoka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-hook-form-mui's Issues

form reset after submit

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary ๐Ÿ’ก

that after submit event is detected, a form should empty all its fields.

Examples ๐ŸŒˆ

const onSubmit = (data) => {
        console.log(data)
        reset()        // example calling method to reset form
    }

[ERROR] Could not resolve "@mui/x-date-pickers/DatePicker"

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

Getting the following error when building the application:

[ERROR] Could not resolve **"@mui/x-date-pickers/DatePicker"**

Expected behavior ๐Ÿค”

No errors

Steps to reproduce ๐Ÿ•น

Steps:

  1. Install the library
  2. Build the project

onError

FormContainer has the onSuccess prop.
What would be the prop to handle form errors?
Is there something like this?
<FormContainer
onError(()=> console.log("This is an error"));
></FormContainer>

Can not find utils in context [workaround]

This is great work, and coming in at Just The Right Time (!!) as I struggle with using Material UI with react-hook-forms !

So I'm trying to use your DatePickerElement, and I get the error: Can not find utils in context

Looking thru your stories and files I see that your DatePickerElement seems to depend on being wrapped in your DateDayjsProvider (which you don't export for me to use...)

So I copied your DateDayjsProvider & added it myself

I then got errors about @date-io/dayjs & dayjs -- which I installed

Then I got an error utils.getYearText is not a function

Googling that took me here: mui/material-ui-pickers#1442

So I downgraded to @date-io/[email protected] and now things work!

Thanks for your very timely work -- it's going to help this project to arrive on time !!

// https://material-ui.com/components/switches/
import { Box, Button } from '@material-ui/core'

// https://www.npmjs.com/package/react-hook-form-mui
import { FormContainer, TextFieldElement, DatePickerElement } from 'react-hook-form-mui'

// copied from inside 'react-hook-form-mui'
import DateDayjsProvider from './DateDayjsProvider'

export const FormEventNew = ({ onSubmit, submitName }
  : { onSubmit: (values: any) => void, submitName: string }) => {

  return (
    <DateDayjsProvider>
      <FormContainer
        defaultValues={{ name: '', date: '' }}
        onSuccess={onSubmit}
      >
        <TextFieldElement name="name" label="Event Name" required />

        <DatePickerElement
          label={'Event Date'}
          name={'required-date-picker'}
          required
        />

        <br />

        <Box>
          <Button variant="contained" color="primary" type="submit">
            {submitName}
          </Button>
        </Box>

      </FormContainer>
    </DateDayjsProvider>
  )
}

"TypeError: Cannot read properties of null (reading 'control')" when using useWatch

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

There is an example in the storybook page for the useWatch method on how to listen to form field changes (stories/FormContainer.stories.tsx). When I try using it in the nextjs example. I am getting an Error:

TypeError: Cannot read properties of null (reading 'control')
    at useWatch (file:///Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-hook-form/dist/index.esm.mjs:296:31)
    at SubComponent (webpack-internal:///./src/pages/index.tsx:24:84)
    at renderWithHooks (/Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5471:16)
    at renderIndeterminateComponent (/Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5544:15)
    at renderElement (/Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5759:7)
    at renderNodeDestructive (/Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5898:11)
    at renderNode (/Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6030:12)
    at renderChildrenArray (/Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5986:7)
    at renderNodeDestructive (/Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5918:7)
    at renderNode (/Users/chris/Work/github/other/react-hook-form-mui/example/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6030:12)
error - TypeError: Cannot read properties of null (reading 'control')

This error only appears when refreshing the page. If there is a bit of a delay at the page load, the form works just fine. So my workaround for now is adding a timeout of one second at page load before rendering the form. I have no idea what causes the issue since using the watcher from react-hook-form directly is working just fine for me.

Expected behavior ๐Ÿค”

No Error when refreshing the page

Steps to reproduce ๐Ÿ•น

Steps:

  1. clone the react-hook-form-mui repo
  2. go to the example folder
  3. add the SubComponent from stories/FormContainer.stories.tsx to the form in src/pages/index.tsx and use it in the form. change the useWatch to the fields that are present in the form or add the extra fields as well
  4. the hot reload is working but try refreshing the page

InputProps on Autocomplete don't do anything

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

I pass startAdornment and endAdornment as InputProps to the AutocompleteElement as follows. All my other props here come from variables.

<AutocompleteElement
  name={varName}
  options={options}
  textFieldProps={{
    placeholder: placeholder,
    InputProps: { startAdornment: <LocationIcon />, endAdornment: null },
  }}
/>

These InputProps are not applied:
Screen Shot 2022-08-01 at 5 02 57 PM

Expected behavior ๐Ÿค”

Using the same code as above, the output should look like this:
Screen Shot 2022-08-01 at 5 04 17 PM

Steps to reproduce ๐Ÿ•น

Edit ComboBox demo โ€” Material UI (forked)

DatePicker problem 1st usage only

The 1st time the DatePicker is used it returns the date BEFORE the selected date

In your Storybook demo - choose default Date Picker and choose a date in next week

The result is the day before the selected date

Do it again (without reloading the page) and it works as expected

Reload the page, repeat the problem

Custom 'required' for simple SelectElement (+ MultiSelectElement on storybook broken)

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary ๐Ÿ’ก

I suspected that the rules={...} prop would work for the SelectElement but it does not seem to?

There is no example for a custom 'required' on the storybook, and the MultiSelectElement does not seem to run either.

Also might you know the best way to programmatically clear form element values to re-trigger the requirement error?

Thanks

Examples ๐ŸŒˆ

No response

Run tests in repo

There is a folder that includes tests but there is no test runner like jest or integration with storybook. I suspect the tests were being ran locally with some ignored folder based on the imports they are using import { FormContainer, MultiSelectElement } from '../_unused'.

@dohomi can you provide some additional details around your testing strategy?

Autocomplete ignores `renderOption` prop

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

If I pass the renderOption prop to the autocompleteProps of the AutocompleteElement, it is completely ignored.

Expected behavior ๐Ÿค”

Passing the renderOption prop should override any other logic for rendering options.

Steps to reproduce ๐Ÿ•น

No response

How to disable Submit on Enter key

I had a problem where the Enter/Return key is causing a submit -- I'm placing a solution here in case others come looking.

This discussion offered some hints on how to prevent such behavior: react-hook-form/react-hook-form#2549

I had to set the onKey into a div inside the FormContainer

  const checkKeyDown = (e) => {
    if (e.key === 'Enter') e.preventDefault()
  }

  return (
    <FormContainer defaultValues={formDefaults} onSuccess={doUpdateData}>
      <div onKeyDown={(e) => checkKeyDown(e)} className={classes.formRoot}>

PasswordRepeat

A core example here mentions PasswordRepeat but nothing like that exists in the Storybook.

In fact, the solution is adding this piece of code from src to Storybook source code preview:
const PasswordRepeat: FunctionComponent = () => {
const { getValues } = useFormContext()
return (
<PasswordElement margin={'dense'}
label={'Password Repeat'}
required
parseError={parseError}
validation={{
validate: (value: string) => {
const { password } = getValues()
return value === password || 'Password should match'
}
}}
name={'password-repeat'}
/>
)
}

Manually typing date into DatePicker causes exception

I assumed that I was doing something wrong but the same thing happens in the Storybook examples...

Uncaught RangeError: Invalid time value
at Date.toISOString ()
at onChange (react-form-hook-mui.esm.js:1)
at Object.handleChange [as onChange] (useMaskedInput.js:60)
at rifm.esm.js:131
at commitHookEffectListMount (react-dom.development.js:20573)
at commitLifeCycles (react-dom.development.js:20634)
at commitLayoutEffects (react-dom.development.js:23426)
at HTMLUnknownElement.callCallback (react-dom.development.js:3945)
at Object.invokeGuardedCallbackDev (react-dom.development.js:3994)
at invokeGuardedCallback (react-dom.development.js:4056)

peer @mui/lab@">= 5.x <6" from [email protected]

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @mui/[email protected]
npm ERR! node_modules/@mui/lab
npm ERR!   @mui/lab@"^5.0.0-alpha.75" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @mui/lab@">= 5.x <6" from [email protected]
npm ERR! node_modules/react-hook-form-mui
npm ERR!   react-hook-form-mui@"^3.1.3" from the root project
npm ERR!

Not sure I understand why this version isn't satisfied

Using npm v8

Styled components application

I'm trying to apply styles to both the SelectElement and MultiSelectElement components, and I've noticed that in multiselects, the root styles are applied to the .MuiInputBase-root rather than the .MuiFormControl-root with the select component. This means that it's difficult to apply styling to the label since it's not a decedent.

I've made a codesandbox with what I'm trying to achieve here: https://codesandbox.io/s/condescending-tereshkova-pvtz6o?file=/src/App.js

Are there any workarounds I can use here? Apologies if this is a dumb question, I'm relatively new to styled components & react in general.

How do I access FormContainer().formContext ?

How can I get to the formContext of FormContainer ?

I want to programmatically disable the Form Submit button until the user has entered 2 of 3 fields (name is required, plus one of: email or phone number)

All of the examples at react-hook-form use formContext and I can't figure out how to access formContext before the submit handler is called.

TextFieldElement doesn't allow defaultValue to be set.

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary ๐Ÿ’ก

We should probably expose the defaultValue from the ControllerProps instead of the one from the TextInput and apply it to the Controller

export type TextFieldElementProps<T extends FieldValues = FieldValues> = Omit<
  TextFieldProps,
  'name' | 'defaultValue'
> & {
  validation?: ControllerProps['rules']
  parseError?: (error: FieldError) => string
} & Pick<ControllerProps<T>, 'control' | 'defaultValue' | 'name'>

If you don't get around to it, I'll try and create a PR.

Examples ๐ŸŒˆ

No response

DateTimePicker support

Add support for DateTimePicker,

I think is possible to use the same implementation of DatePicker :)

onChange doesn't fire for TextFieldElement

Hi,

I am not able to figure it out how to fire the onChange event for TextFieldElement component.

Here is the Example I have tried.

Could you please let me know if anything special required.

Thanks for the plugin.

new Slider component

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary ๐Ÿ’ก

I created my own slider component that I am using. Can I create a pull request to include this slider component upstream?

Examples ๐ŸŒˆ

<SliderElement
  name="slider"
  label="Slider"
  min={0}
  max={10}
  marks
/>

Custom error text for TextFieldElement

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary ๐Ÿ’ก

Hi โค๏ธ!
I Can't find how to set custom text error for TextFieldElement. Is it possible?

Examples ๐ŸŒˆ

No response

DatePickerElement bugged when entering the date by keyboard

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

First of all thank you for creating this amazing library!

My problem is when I try to write the date by my choice into DatePickerElement by keyboard. The input acts weird, the video shows example when I try to enter date 01/05/2000. I think that the main reason of this behaviour is the weird cursor move.

tadaaa.webm

Thank you for your time!

Expected behavior ๐Ÿค”

The DatePickerElement should enter 01/05/2000 into the input... same input as I wrote.

Steps to reproduce ๐Ÿ•น

Steps:

  1. Go to storybook.
  2. Enter date by your choice using keyboard.

Clean `peerDependencies`

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

โžค YN0000: โ”Œ Resolution step
โžค YN0002: โ”‚ test-react-hook-form-mui@workspace:. doesn't provide @mui/icons-material (p6b997), requested by react-hook-form-mui
โžค YN0002: โ”‚ test-react-hook-form-mui@workspace:. doesn't provide @mui/x-date-pickers (p983ee), requested by react-hook-form-mui
โžค YN0002: โ”‚ test-react-hook-form-mui@workspace:. doesn't provide typescript (p0935d), requested by react-hook-form-mui
โžค YN0000: โ”‚ Some peer dependencies are incorrectly met; run yarn explain peer-requirements <hash> for details, where <hash> is the six-letter p-prefixed code
โžค YN0000: โ”” Completed
โžค YN0000: โ”Œ Fetch step
โžค YN0000: โ”” Completed
โžค YN0000: โ”Œ Link step
โžค YN0000: โ”‚ ESM support for PnP uses the experimental loader API and is therefore experimental
โžค YN0000: โ”” Completed
โžค YN0000: Done with warnings

Possible Fix

  • @mui/icons-material and @mui/x-date-pickers dependencies should be added as peerDependenciesMeta in package.json:
"peerDependenciesMeta": {
  "@mui/icons-material": {
    "optional": true
  },
  "@mui/x-date-pickers": {
    "optional": true
  } 
}
  • typescript is already in devDependencies, it's really used or it should be removed from peerDependencies?

Note: by the way, peerDependencies/peerDependenciesMeta should be added in Readme as info

Expected behavior ๐Ÿค”

No yarn warnings in console

Steps to reproduce ๐Ÿ•น

Steps:

  1. yarn init -y
  2. yarn set version canary
  3. yarn add @mui/material react react-dom react-hook-form react-hook-form-mui
  4. See console output

Use split bundle to reduce dependency requirements

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary ๐Ÿ’ก

Currently the build version is using a single compiled file which makes the requirement on @mui/icons-material and @mui/x-date-pickers a requirement. The package.json indicates that they are meant to be optional: https://github.com/dohomi/react-hook-form-mui/blob/master/package.json#L44-L51

We don't use the optional libraries but it seems they are required when using the package.

Examples ๐ŸŒˆ

Maybe move to esm packages so we can actually import the components directly?

import TextInputElement from 'react-hook-form-mui/TextInputElement' or something like that?

How are you meant to display custom errors?

Based on this function it seems that this is either not possible, or not ergonomic:

const getErrorMessages = (name: string, errors: any, parseError?: Function) => {
const fieldError = getNestedValue(errors, name) || undefined
const errorType: string | undefined = fieldError?.type
if (Array.isArray(fieldError)) {
console.error('Unexpected field error', fieldError)
}
if (!errorType) return
return parseError ? parseError(errorType) : `This field is ${errorType}`
}

It seems like the message field should be returned by default, not the type field. Or, at least, the whole error should be passed to the parseError so that a function can be provided to pass the correct thing.

I feel like parseError should just be something like (errors) => getPath(fieldName, errors) by default, or is should be possible to define a form-wide parseError in FormContainer.

I could make a pull request if that would help. As it is, getErrorMessages seems too opinionated.

Default labelkey and options prop type definitons for SelectElement do not match

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

must specify labelkey='title' on SelectElement if I use the { id: string | number, title: string | number }[] type defined for options

Expected behavior ๐Ÿค”

default labelkey should match the options prop definition for SelectElement

add support for resolvers

very impressive work! How would you go about adding resolvers, such as yup or joi, into this?

I've done something similar in another project but didn't publish as it's own npm package, appreciate what you've done in here!

Storybook is not working anymore since 3.5.0

Hi @dohomi

your latest release 3.5.0 does break building our storybook. Using 3.4.0 all is working as expected.

This is the error log:

info @storybook/react v6.4.22
info 
info => Loading presets
info => Serving static files from ././public at /
info => Using implicit CSS loaders
info => Using default Webpack5 setup
<i> [webpack-dev-middleware] wait until bundle finished
10% building 0/1 entries 0/0 dependencies 0/0 modules
info => Cleared cached manager config
<i> [webpack-dev-middleware] wait until bundle finished
17% building 2/16 entries 5400/5716 dependencies 664/1715 modulesassets by chunk 4.31 MiB (id hint: vendors)
  assets by status 3.95 MiB [big]
    asset vendors-node_modules_storybook_addon-actions_dist_esm_register_js-node_modules_storybook_addo-7c62db.manager.bundle.js 3.59 MiB [emitted] [big] (id hint: vendors)
    asset vendors-node_modules_storybook_components_dist_modern_ScrollArea_OverlayScrollbars_js.manager.bundle.js 366 KiB [emitted] [big] (id hint: vendors)
  asset vendors-node_modules_storybook_components_dist_modern_syntaxhighlighter_syntaxhighlighter_js.manager.bundle.js 190 KiB [emitted] (id hint: vendors)
  asset vendors-node_modules_storybook_components_dist_modern_tooltip_WithTooltip_js.manager.bundle.js 108 KiB [emitted] (id hint: vendors)
  asset vendors-node_modules_storybook_components_dist_modern_controls_Color_js.manager.bundle.js 61.9 KiB [emitted] (id hint: vendors)
  asset vendors-node_modules_storybook_components_dist_modern_ScrollArea_GlobalScrollAreaStyles_js.manager.bundle.js 13.6 KiB [emitted] (id hint: vendors)
asset runtime~main.manager.bundle.js 14.2 KiB [emitted] (name: runtime~main)
asset index.html 3.03 KiB [emitted]
asset main.manager.bundle.js 1.52 KiB [emitted] (name: main)
asset node_modules_unfetch_dist_unfetch_js.manager.bundle.js 1.27 KiB [emitted]
Entrypoint main [big] 3.61 MiB = runtime~main.manager.bundle.js 14.2 KiB vendors-node_modules_storybook_addon-actions_dist_esm_register_js-node_modules_storybook_addo-7c62db.manager.bundle.js 3.59 MiB main.manager.bundle.js 1.52 KiB
orphan modules 1.34 MiB [orphan] 346 modules
runtime modules 8.71 KiB 15 modules
javascript modules 3.88 MiB 711 modules
json modules 1.52 KiB
  ./node_modules/character-entities-legacy/index.json 1.24 KiB [built] [code generated]
  ./node_modules/character-reference-invalid/index.json 289 bytes [built] [code generated]
manager (webpack 5.72.1) compiled successfully in 7354 ms
99% done plugins webpack-hot-middlewarewebpack built preview 9d0b181ee24f6071c08e in 13884ms
ModuleNotFoundError: Module not found: Error: Can't resolve '@mui/icons-material/Cancel' in '/Workspace/node_modules/react-hook-form-mui/dist'
Did you mean 'Cancel.js'?
BREAKING CHANGE: The request '@mui/icons-material/Cancel' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
    at /Workspace/node_modules/webpack/lib/Compilation.js:2016:28
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (/Workspace/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (/Workspace/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:975:5
    at /Workspace/node_modules/neo-async/async.js:6883:13
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:892:17
    at finishResolved (/Workspace/node_modules/enhanced-resolve/lib/Resolver.js:294:11)
    at /Workspace/node_modules/enhanced-resolve/lib/Resolver.js:362:25
    at /Workspace/node_modules/enhanced-resolve/lib/Resolver.js:434:24
    at eval (eval at create (/Workspace/node_modules/enhanced-resolve/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
resolve '@mui/icons-material/Cancel' in '/Workspace/node_modules/react-hook-form-mui/dist'
  Parsed request is a module
  using description file: /Workspace/node_modules/react-hook-form-mui/package.json (relative path: ./dist)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /Workspace/node_modules/react-hook-form-mui/dist/node_modules doesn't exist or is not a directory
      /Workspace/node_modules/react-hook-form-mui/node_modules doesn't exist or is not a directory
      /Workspace/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /Workspace/node_modules
        existing directory /Workspace/node_modules/@mui/icons-material
          using description file: /Workspace/node_modules/@mui/icons-material/package.json (relative path: .)
            using description file: /Workspace/node_modules/@mui/icons-material/package.json (relative path: ./Cancel)
              Field 'browser' doesn't contain a valid alias configuration
              /Workspace/node_modules/@mui/icons-material/Cancel doesn't exist
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
ModuleNotFoundError: Module not found: Error: Can't resolve '@mui/icons-material/Visibility' in '/Workspace/node_modules/react-hook-form-mui/dist'
Did you mean 'Visibility.js'?
BREAKING CHANGE: The request '@mui/icons-material/Visibility' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
    at /Workspace/node_modules/webpack/lib/Compilation.js:2016:28
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (/Workspace/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (/Workspace/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:975:5
    at /Workspace/node_modules/neo-async/async.js:6883:13
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:892:17
    at finishResolved (/Workspace/node_modules/enhanced-resolve/lib/Resolver.js:294:11)
    at /Workspace/node_modules/enhanced-resolve/lib/Resolver.js:362:25
    at /Workspace/node_modules/enhanced-resolve/lib/Resolver.js:434:24
    at eval (eval at create (/Workspace/node_modules/enhanced-resolve/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
resolve '@mui/icons-material/Visibility' in '/Workspace/node_modules/react-hook-form-mui/dist'
  Parsed request is a module
  using description file: /Workspace/node_modules/react-hook-form-mui/package.json (relative path: ./dist)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /Workspace/node_modules/react-hook-form-mui/dist/node_modules doesn't exist or is not a directory
      /Workspace/node_modules/react-hook-form-mui/node_modules doesn't exist or is not a directory
      /Workspace/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /Workspace/node_modules
        existing directory /Workspace/node_modules/@mui/icons-material
          using description file: /Workspace/node_modules/@mui/icons-material/package.json (relative path: .)
            using description file: /Workspace/node_modules/@mui/icons-material/package.json (relative path: ./Visibility)
              Field 'browser' doesn't contain a valid alias configuration
              /Workspace/node_modules/@mui/icons-material/Visibility doesn't exist
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory
ModuleNotFoundError: Module not found: Error: Can't resolve '@mui/icons-material/VisibilityOff' in '/Workspace/node_modules/react-hook-form-mui/dist'
Did you mean 'VisibilityOff.js'?
BREAKING CHANGE: The request '@mui/icons-material/VisibilityOff' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
    at /Workspace/node_modules/webpack/lib/Compilation.js:2016:28
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:798:13
    at eval (eval at create (/Workspace/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:10:1)
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:270:22
    at eval (eval at create (/Workspace/node_modules/webpack/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:9:1)
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:434:22
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:116:11
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:670:25
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:855:8
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:975:5
    at /Workspace/node_modules/neo-async/async.js:6883:13
    at /Workspace/node_modules/webpack/lib/NormalModuleFactory.js:892:17
    at finishResolved (/Workspace/node_modules/enhanced-resolve/lib/Resolver.js:294:11)
    at /Workspace/node_modules/enhanced-resolve/lib/Resolver.js:362:25
    at /Workspace/node_modules/enhanced-resolve/lib/Resolver.js:434:24
    at eval (eval at create (/Workspace/node_modules/enhanced-resolve/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
resolve '@mui/icons-material/VisibilityOff' in '/Workspace/node_modules/react-hook-form-mui/dist'
  Parsed request is a module
  using description file: /Workspace/node_modules/react-hook-form-mui/package.json (relative path: ./dist)
    Field 'browser' doesn't contain a valid alias configuration
    resolve as module
      /Workspace/node_modules/react-hook-form-mui/dist/node_modules doesn't exist or is not a directory
      /Workspace/node_modules/react-hook-form-mui/node_modules doesn't exist or is not a directory
      /Workspace/node_modules/node_modules doesn't exist or is not a directory
      looking for modules in /Workspace/node_modules
        existing directory /Workspace/node_modules/@mui/icons-material
          using description file: /Workspace/node_modules/@mui/icons-material/package.json (relative path: .)
            using description file: /Workspace/node_modules/@mui/icons-material/package.json (relative path: ./VisibilityOff)
              Field 'browser' doesn't contain a valid alias configuration
              /Workspace/node_modules/@mui/icons-material/VisibilityOff doesn't exist
      /Users/node_modules doesn't exist or is not a directory
      /node_modules doesn't exist or is not a directory

WARN Broken build, fix the error above.
WARN You may need to refresh the browser.

This is my package.json

  "dependencies": {
    "@emotion/cache": "11.7.1",
    "@emotion/react": "11.9.0",
    "@emotion/server": "11.4.0",
    "@emotion/styled": "11.8.1",
    "@fontsource/roboto": "4.5.7",
    "@hookform/resolvers": "2.8.10",
    "@mui/icons-material": "5.8.0",
    "@mui/lab": "5.0.0-alpha.82",
    "@mui/material": "5.8.0",
    "commander": "9.2.0",
    "date-fns": "2.28.0",
    "deepmerge": "4.2.2",
    "dotenv-cli": "5.1.0",
    "import-jsx": "4.0.1",
    "ink": "3.2.0",
    "next": "12.1.6",
    "next-auth": "4.3.4",
    "node-cache": "5.1.2",
    "nodemailer": "6.7.5",
    "prop-types": "15.8.1",
    "react": "17.0.2 && <18",
    "react-dom": "17.0.2 && <18",
    "react-hook-form": "7.31.1",
    "react-hook-form-mui": "3.5.0",
    "react-tracked": "1.7.9",
    "vest": "4.4.0"
  },
  "devDependencies": {
    "@babel/core": "7.17.12",
    "@storybook/addon-actions": "6.4.22",
    "@storybook/addon-controls": "6.4.22",
    "@storybook/addon-docs": "6.4.22",
    "@storybook/addon-essentials": "6.4.22",
    "@storybook/addon-interactions": "6.4.22",
    "@storybook/addon-links": "6.4.22",
    "@storybook/builder-webpack5": "6.4.22",
    "@storybook/manager-webpack5": "6.4.22",
    "@storybook/preset-scss": "1.0.3",
    "@storybook/react": "6.4.22",
    "@storybook/testing-library": "0.0.11",
    "@testing-library/jest-dom": "5.16.4",
    "@testing-library/react": "12.1.4 && <13",
    "@testing-library/user-event": "14.2.0",
    "@types/jest": "27.5.1",
    "@types/node": "17.0.34",
    "@types/react": "17.0.43 && <18",
    "@typescript-eslint/eslint-plugin": "5.25.0",
    "@typescript-eslint/parser": "5.25.0",
    "@typescript-eslint/typescript-estree": "5.25.0",
    "babel-jest": "28.1.0",
    "babel-loader": "8.2.5",
    "css-loader": "6.7.1",
    "docsify-cli": "4.4.4",
    "eslint": "8.15.0",
    "eslint-config-airbnb": "19.0.4",
    "eslint-config-next": "12.1.6",
    "eslint-config-prettier": "8.5.0",
    "eslint-plugin-import": "2.26.0",
    "eslint-plugin-mui-unused-classes": "github:4commerce-technologies-AG/eslint-plugin-material-ui-unused-classes",
    "eslint-plugin-prettier": "4.0.0",
    "eslint-plugin-storybook": "0.5.12",
    "identity-obj-proxy": "3.0.0",
    "jest": "28.1.0",
    "jest-environment-jsdom": "28.1.0",
    "jest-transform-yaml": "1.0.0",
    "jest-watch-typeahead": "1.1.0",
    "js-yaml": "4.1.0",
    "jsdoc-babel": "0.5.0",
    "jsdoc-to-markdown": "7.1.1",
    "next-multilingual-alternate": "github:4commerce-technologies-AG/next-multilingual-alternate#0.10.3-stable",
    "prettier": "2.6.2",
    "react-test-renderer": "17.0.2 && <18",
    "sass": "1.51.0",
    "sass-loader": "12.6.0",
    "storybook-addon-next-router": "3.1.1",
    "style-loader": "3.3.1",
    "typescript": "4.6.4",
    "yaml-loader": "0.8.0"
  }

I am using 3.4.0 instead currently again to continue our development

List of improvments

Hello

I'm currently waiting for my new MacBook, so I don't want to start any big project. I could help develop this open-source project ๐Ÿ˜„

So we can start with simple things to the more advance.

  1. Move the changelog to a separate file.
  2. Add some badges
    image
  3. Create a logo (logo RHF + logo MUI)
  4. Add eslint + prettier
  5. Add autocomplete support
  6. Better issue templates (like RHF)
    image
  7. Stackblitz examples

Ofc, I will create separate PRs.

cannot call api

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

in autocomplete element cannot call api values.

Expected behavior ๐Ÿค”

No response

Steps to reproduce ๐Ÿ•น

Steps:

proposal-nullish-coalescing-operator compile error

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

when I add loaders plugins @babel/plugin-proposal-nullish-coalescing-operator

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "useBuiltIns": "usage",
        "corejs": { "version": 3, "proposals": true }
      }
    ]
  ],
  "plugins": ["@babel/plugin-proposal-nullish-coalescing-operator"]
}

but has this error

Failed to compile.

./node_modules/react-hook-form-mui/dist/esm/index.js 36:18
Module parse failed: Unexpected token (36:18)
File was processed with these loaders:
 * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|       return e.createElement(v, { ...a,
|         name: i,
>         value: s ?? "",
|         onChange: m,
|         onBlur: C,

Expected behavior ๐Ÿค”

how to fix this "proposal-nullish-coalescing-operator" error

Steps to reproduce ๐Ÿ•น

Steps:

Autocomplete not returning complete object but only returns "id"

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior ๐Ÿ˜ฏ

According to this codesandbox, we are able to return complete object as value for autocomplete, using:

onChange={([event, data]) => {
        return data;
      }}

The current implementation of autocomplete:

  1. Prohibits to have any data set without an id key. If we do not have an id key, then the the autocomplete label does not hold value. It resets onBlur
  2. Because of this, if I want to return a complete object for AutoComplete, I am not able to and it returns id.
  3. We cannot add an onChange on the controller like we can in the codesandbox

Expected behavior ๐Ÿค”

We should be able to add onChange on the controller wrapping the autocomplete or we should be able to return complete object from the autocomplete without label getting reset on onBlur

Steps to reproduce ๐Ÿ•น

Steps:

Use mock data:

export interface IParty {
  id: string;
  name: string;
  address: string;
  gstin: string;
}


const MD_PARTIES: IParty[] = [
  {
    id: '1',
    name: 'APEX PVT. LTD.',
    address:
      'ABCD',
    gstin: '1234'
  },
  {
    id: '2',
    name: 'IE AUTO PVT. LTD.',
    address: 'EFGH',
    gstin: '5678'
  },
];

  /**
   * Autocomplete prop
   * @description uses "name" key from the object as the autocomplete option label
   */
  const autoCompleteProps = {
    getOptionLabel: (option: IParty) => option.name
  };
  
 <AutocompleteElement
              label="Party"
              name="party"
              autocompleteProps={autoCompleteProps}
              options={MD_PARTIES}
            />

Reformat repo using eslint rools

Currently, eslint is throwing a lot of obvious errors like:
image

They're easy to fix (most of them are auto-fixable). But the diff will be huuuuge. That's why I want it in a separate issue.

So on this ticket, I'll:

  1. Add sonarJS plugin for eslint.
  2. Fix all eslint errors.
  3. (Optionally) Provide a GH action that runs eslint before merging to master.

@dohomi Let me know what you think about that. If you wanna provide some other eslint rules, feel free ๐Ÿ˜ƒ

i18n support

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary ๐Ÿ’ก

Thanks for this helpful library.
It would be great if it was possible to translate the standard error messages for validation rules (required and for email field type). Currently it can be done only with passing own validation config object to all component instances or by overriding all components code.

Examples ๐ŸŒˆ

New property for FormContainer which could receive default error messages or other way to declare them would be appreciated.

[Feature Request] Add Autocomplete component and introduce example of async call

I don't know if you can do this...

Please consider somehow integrating https://www.npmjs.com/package/react-places-autocomplete, or: https://www.npmjs.com/package/material-ui-autocomplete-google-places,

I struggled through many different versions before finding one I could get working. (and it does work quite well once you get it going) The one I got working is a bit of a mess, I know you could do much better !!

It would be really nice for my form to have an address component whose data was gathered automatically

Thanks for your time and attention !

Release information and tags

Dear Dominic @dohomi

thanks providing this component and your effort on it.

Could you please establish a way to describe changes that were included in new releases and tag them?

Currently on npmjs there is version 3.3.0 but I can't get from what sources you have built that. What it be possible for you to tag the branch on releasing an write some short "changes".

I am pretty sure that would be welcome by others as well.

Again thanks
Tom

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.