-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Enhance getInputProps to allow passing of non-overridden props #35034
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
Conversation
Test Results SummaryCommit SHA: 6519e81
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
joshuatf
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting that we have more upcoming work (I also have an open PR) that will benefit from being able to pass in additional handlers without overriding the Form's handlers.
| regularPriceProps?.onChange( sanitizedValue ); | ||
| } } | ||
| value={ formatCurrencyDisplayValue( regularPriceProps?.value, currencyConfig, formatAmount ) } | ||
| onBlur={ () => setValue( 'regular_price', sanitizePrice( regularPriceProps.value ) ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@octaedro I moved the sanitization to onBlur. I think this is a little bit more conventional as I was worried about input being sanitized as it was typed could lead to odd behavior.
But please let me know if I broke anything here or if this needs to be sanitized as we type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me! Good idea!
| ? 'prefix' | ||
| : 'suffix'; | ||
|
|
||
| return { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My goal was to unwrap some of these so that we can:
- More easily follow where props are being passed
- Reduce the knowledge of form handlers in this function
- Reduce overall logic in this function
6dd3ccc to
9298538
Compare
|
@octaedro Thanks for the ping on rebasing this one in Slack! After rebasing, a lot of TS issues cropped up that I think we were able to errantly bypass before. I added a @mdperez86 since this also affects a lot of your recent additions around dimensions, it would be great to get your 👀 on this as well. |
| }; | ||
| } | ||
|
|
||
| function getCheckboxProps< Value = Values[ keyof Values ] >( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be getCheckboxInputProps or getCheckboxControlProps instead? The reason I ask is we'll probably want to introduce a getSelectProps which sounds odd and could be interpreted the wrong way. Also okay leaving it as is, but wanted to get some feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would lean towards getCheckboxControlProps. But I'm also ok leaving it as it is now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that makes sense too since we're really creating props specifically for our controls 👍
| { ...getInputProps( 'name', { | ||
| onBlur: setSkuIfEmpty, | ||
| } ) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
octaedro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job @joshuatf! This is testing well here and the code looks good.
There is a small visual error with the Feature this product checkbox, the rest looks great!
6210905 to
ad7e1b1
Compare
octaedro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @joshuatf for addressing the changes! The initialValues issue was a pretty tricky thing to deal with.
Good job! ![]()
e03cc19 to
6519e81
Compare
octaedro
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
|
Hi @joshuatf, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|

All Submissions:
Changes proposed in this Pull Request:
Previously, adding an
onChangehandler or anything else that collided withgetInputPropswould require recallinggetInputProps.someFunctioninside the new handler. This PR introduces a second argument togetInputPropswhich passes props to the control without overriding the original handlers where possible.Some props will not override the original handler (e.g., if you pass on
onChangeit will be combined with theFormcomponent'sonChange) and some will override (e.g.,valuecan not be combined and the consumer prop will override the original value).This PR also uncovered numerous TS issues, so a
getCheckboxPropswas introduced into theFormcomponent to omit invalid props (e.g.,valuefor checkboxes). More specific prop getters are probably in order (getSelectProps), but I think we can iterate on these as we go.Finally, a
sanitizemethod was added as part of the optional consumer input props. This is a shortcut to sanitizing the input value and handling changes on blur.TL;DR:
getInputPropsnow takes a second argument to combine/override props where necessarysanitizemethod can be added to an input to handle sanitization on blurgetCheckboxPropswas introduced for props specific to checkboxesCloses #34996 .
How to test the changes in this Pull Request:
Products -> Add new (MVP)Other information:
pnpm --filter=<project> run changelog add?FOR PR REVIEWER ONLY: