Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: React-hook-Form v7 for ionic-react 6 IonInput props is not assignable #24489

Closed
4 of 6 tasks
joeldacuma opened this issue Dec 27, 2021 · 8 comments
Closed
4 of 6 tasks
Labels
package: core @ionic/core package package: react @ionic/react package type: bug a confirmed bug report

Comments

@joeldacuma
Copy link

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

IonInput is not assigning types of props using register function of react-hook-form

Expected Behavior

props of register function using react-hook-form should be assignable to IonInput

Steps to Reproduce

import { useForm } from 'react-hook-form';

const { control, handleSubmit, register, setValue } = useForm({
defaultValues: {
email: ''
}
});

const {ref, onChange, ...props} = register('email', {
required: true,
})

<IonItem>
  <IonLabel>Email</IonLabel>
      <IonInput  {...props} />         
  </IonItem>

Code Reproduction URL

No response

Ionic Info

Ionic:

Ionic CLI : 6.18.1 (/Users/joeldacuma/.nvm/versions/node/v14.17.0/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/react 6.0.1

Capacitor:

Capacitor CLI : 2.4.6
@capacitor/android : 2.4.6
@capacitor/core : 2.4.6
@capacitor/ios : 2.4.6

Utility:

cordova-res : not installed globally
native-run : not installed globally

System:

NodeJS : v14.17.0
npm : 6.14.13
OS : macOS Monterey

Additional Information

No response

@ionitron-bot ionitron-bot bot added the holiday triage issues that were created during holiday period label Dec 27, 2021
@ionitron-bot
Copy link

ionitron-bot bot commented Dec 27, 2021

Thanks for the issue! This issue has been labeled as holiday triage. With the winter holidays quickly approaching, much of the Ionic Team will soon be taking time off. During this time, issue triaging and PR review will be delayed until the team begins to return. After this period, we will work to ensure that all new issues are properly triaged and that new PRs are reviewed.

In the meantime, please read our Winter Holiday Triage Guide for information on how to ensure that your issue is triaged correctly.

Thank you!

@joeldacuma joeldacuma changed the title bug: React-hook-Form v7 for ionic-react 6 IonInput number is not assignable bug: React-hook-Form v7 for ionic-react 6 IonInput props is not assignable Dec 27, 2021
@sean-perkins
Copy link
Contributor

Hello @joeldacuma thanks for reporting this issue.

Can you help explain to me the reasoning behind why ion-input should have the exact type signature as react-hook-form?

In your pseudo code you have left out what props is tied to, so I'm having a difficult time following the example.

An example repository would be great to visualize the issue.

@sean-perkins sean-perkins added the needs: reply the issue needs a response from the user label Jan 5, 2022
@ionitron-bot ionitron-bot bot removed the holiday triage issues that were created during holiday period label Jan 5, 2022
@joeldacuma
Copy link
Author

joeldacuma commented Jan 5, 2022

Hello @joeldacuma thanks for reporting this issue.

Can you help explain to me the reasoning behind why ion-input should have the exact type signature as react-hook-form?

In your pseudo code you have left out what props is tied to, so I'm having a difficult time following the example.

An example repository would be great to visualize the issue.

Hi @sean-perkins ,

there is a compatibility issue for the max property for react-hook-form and IonInput for Ionic 6. This is working fine using Ionic 5 with react-hook-form v7.

Here is the reference for Ionic5 react-hook-form v7:
https://github.com/alanmontgomery/ionic-react-hook-form-example/blob/main/src/pages/Home.js

Here is the error I encountered in Ionic6:

Screen Shot 2022-01-05 at 1 01 44 PM

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Jan 5, 2022
@sean-perkins
Copy link
Contributor

Thanks for the extra detail. I'm unable to pinpoint a specific change in v6 that would have regressed this behavior. The type signature for min/max has aligned with the HTML Spec for being a string | date (date string) since April 2018.

It looks like the type signature from the implementation using react-hook-form is incorrect (string | number | undefined).

Could you isolate this behavior in a repository, with a branch on v5 and a branch on v6?

@sean-perkins sean-perkins added the ionitron: needs reproduction a code reproduction is needed from the issue author label Jan 12, 2022
@ionitron-bot
Copy link

ionitron-bot bot commented Jan 12, 2022

Thanks for the issue! This issue has been labeled as needs reproduction. This label is added to issues that need a code reproduction.

Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed.

If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue.

For a guide on how to create a good reproduction, see our Contributing Guide.

@ionitron-bot ionitron-bot bot removed the triage label Jan 12, 2022
@sean-perkins
Copy link
Contributor

Follow-up on this issue since I haven't heard back on the reproduction. I've been able to validate this issue exists with react-hook-forms and a standard form implementation with Ionic React.

I'll capture this as a bug and see if adjusting the type signature for the min/max solves the incompatibilities.

Thanks!

@sean-perkins sean-perkins added package: core @ionic/core package package: react @ionic/react package type: bug a confirmed bug report and removed ionitron: needs reproduction a code reproduction is needed from the issue author labels Jan 26, 2022
@sean-perkins
Copy link
Contributor

PR #24657 will fix the type conflict between Ionic React and react-hook-form.

In the interim, you can use this dev build to test with:

npm i @ionic/[email protected]

You may need to delete @ionic/core from node_modules prior to installing, so that the correct package is installed with the updated types.

@ionitron-bot
Copy link

ionitron-bot bot commented Feb 26, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Feb 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
package: core @ionic/core package package: react @ionic/react package type: bug a confirmed bug report
Projects
None yet
Development

No branches or pull requests

1 participant