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

[Enhancement]: Form component input props should allow passing of custom callbacks #34996

Closed
joshuatf opened this issue Oct 7, 2022 · 0 comments · Fixed by #35034
Closed
Assignees
Labels
focus: components Issues related to @woocommerce/* packages type: enhancement The issue is a request for an enhancement.

Comments

@joshuatf
Copy link
Contributor

joshuatf commented Oct 7, 2022

Describe the solution you'd like

For the Form component getInputProps, we occasionally have to override an event like onBlur.

<TextControl
  { ...getInputProps( 'field_name' ) }
  onBlur={ myOnBlurHandler }
/>

The problem is that this overrides the default getInputProps onBlur method and now manually needs to be called:

<TextControl
  { ...getInputProps( 'field_name' ) }
  onBlur={ () => {
    myOnBlurHandler();
    getInputProps( 'field_name' ).onBlur();
  }
/>

To make things a bit easier on consumers, we could consider an optional second argument that adds props to the event without overriding the Form's handlers. E.g.,

<TextControl
  { ...getInputProps( 'field_name', { onBlur: myOnBlurHandler } ) }
/>

Describe alternatives you've considered

Manually calling the input form's handler is the current way of handling this, but it is more prone to errors and more cumbersome to write.

getInputProps( 'field_name' ).onBlur();

Additional context

The new product management experience has been creating utils like getTextControlProps and getInputControlProps that handle specific items like classes. It would be good to move some of this logic back to the Form package.

@joshuatf joshuatf added type: enhancement The issue is a request for an enhancement. focus: components Issues related to @woocommerce/* packages labels Oct 7, 2022
@joshuatf joshuatf self-assigned this Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
focus: components Issues related to @woocommerce/* packages type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant