-
Notifications
You must be signed in to change notification settings - Fork 221
Update ValidatedTextInput TypeScript & move to @woocommerce/blocks-checkout
#7583
Conversation
@@ -6,8 +6,8 @@ import classNames from 'classnames'; | |||
import type { ReactElement, HTMLProps } from 'react'; | |||
|
|||
interface LabelProps extends HTMLProps< HTMLElement > { | |||
label?: string; | |||
screenReaderLabel?: string; | |||
label?: string | undefined; |
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.
This is required because of the changes in #5312 where "exactOptionalPropertyTypes": true
was added to tsconfig.base.json
. The same applies for other instances where I added | undefined
to optional props.
@@ -46,7 +57,7 @@ const ValidatedTextInput = ( { | |||
const inputRef = useRef< HTMLInputElement >( null ); | |||
|
|||
const { setValidationErrors, hideValidationError, clearValidationError } = | |||
dispatch( VALIDATION_STORE_KEY ); | |||
useDispatch( VALIDATION_STORE_KEY ); |
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.
We can use the hook version here, since we're within a React component.
The release ZIP for this PR is accessible via:
|
TypeScript Errors ReportFiles with errors: 440
packages/checkout/blocks-registry/test/index.js
packages/checkout/components/text-input/test/validated-text-input.tsx packages/checkout/components/totals/item/index.tsx packages/checkout/filter-registry/test/index.js |
if ( | ||
isString( passedErrorMessage ) && | ||
passedErrorMessage !== '' && | ||
isObject( passedErrorMessage ) |
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.
Previously, if validationError
was not an object, this would error because you can't access .message
on undefined.
Script Dependencies ReportThe
This comment was automatically generated by the |
I think these errors are unrelated to my changes! |
We export these components from packages/checkout/index.js instead
3a26598
to
43982fa
Compare
Size Change: -7.9 kB (-1%) Total Size: 991 kB
ℹ️ View Unchanged
|
TypeScript Errors ReportFiles with errors: 440
packages/checkout/blocks-registry/test/index.js
packages/checkout/components/text-input/test/validated-text-input.tsx packages/checkout/components/totals/item/index.tsx packages/checkout/filter-registry/test/index.js |
packages/checkout/components/text-input/test/validated-text-input.tsx
Outdated
Show resolved
Hide resolved
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 for the detailed commit by commit PR Thomas, it was really helpful to understand the refactor.
TypeScript Errors ReportFiles with errors: 440
assets/js/atomic/blocks/product-elements/summary/edit.js
assets/js/atomic/blocks/product-elements/summary/index.js assets/js/blocks/cart/cart-line-items-table/cart-line-item-row.tsx packages/checkout/blocks-registry/test/index.js packages/checkout/components/text-input/test/validated-text-input.tsx packages/checkout/components/totals/item/index.tsx packages/checkout/filter-registry/test/index.js |
…heckout` (woocommerce#7583) * Move ValidatedTextInput and ValidationInputError to checkout package * Include checkout package in tsconfig file * Remove unnecessary index file We export these components from packages/checkout/index.js instead * Import ValidatedTextInput & ValidationInput error from checkout package * Only add validationError.message when validationError is an object * Explicitly add undefined to optional props * Import isObject to test validationError * Extend the HTML Input element attributes * Use more performant useDispatch instead of dispatch * Export component without withInstanceId hoc for testing * Add tests for ValidatedTextInput * bot: update checkstyle.xml * Rename export of unwrapped component to have __ Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This PR moves
ValidatedTextInput
,TextInput
, andValidationInputError
to the@woocommerce/blocks-checkout
package.Fixes #7445
Previously this was not possible de to validation data being stored in a context, but now since it lives in
wc/store/validation
it can be moved to the package.This will make it easier for extensions to integrate with the blocks by offering the same UI component that we use in the blocks. Previous integrations had to recreate this component themselves.
I have annotated my changes in the file review screen which I hope will be helpful.
Testing
Automated Tests
User Facing Testing
Please ensure you can check out correctly and that correct validation errors are displayed when you use invalid inputs on the Checkout block.
WooCommerce Visibility
Changelog