-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
Disable action buttons when product form is invalid #34658
Conversation
Test Results SummaryCommit SHA: 6badcf9
To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
@@ -217,7 +226,7 @@ export const ProductFormActions: React.FC = () => { | |||
<MenuItem | |||
onClick={ onTrash } | |||
isDestructive | |||
disabled={ ! values.id } | |||
disabled={ ! isValidForm || ! values.id } |
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 this action should be allowed even if the form is not valid. Leaving this line how it was before should be enough.
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.
Your are right @octaedro, this change is done now.
But my suggestion is to hide the Move to trash
action button from the creation page because it does not make sense to show an action to an user that will never be enabled in that page. That action is only needed in the edition page. Does that make sense for you @pmcpinto and @jarekmorawski?
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.
It does. 👍 We can hide it for now and bring it back if we hear from the users they need it (which I don't think will happen). We can only show the button once the product is saved as draft or published.
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.
Good job @mdperez86! I just left a small comment. Other than that the code looks good and tests well here.
1f9dc4b
to
d873e8a
Compare
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 @mdperez86 for adding the change! LGTM 🚀
Can we hide the slug when the validation message is shown? It currently doesn't look very good when both of them are in the form. |
d873e8a
to
26085e5
Compare
Looks good, @mdperez86 💪 One more small thing: can we disable the arrow in the split button when all options inside are unavailable? We'd re-enable it if at least 1 option there is active. |
baae459
to
da11ddf
Compare
This is not specific to this PR... it appears to be the default of how Gutenberg Button is styled... I do not care for how the button still appears interactive even when disabled. It reacts when you click on it. This could be confusing. /cc @jarekmorawski |
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! Especially with the tests.
Left a comment asking for the publish menu items test to be tweaked so that it doesn't depend on menu item order.
plugins/woocommerce-admin/client/products/sections/product-details-section.tsx
Show resolved
Hide resolved
plugins/woocommerce-admin/client/products/test/product-form-actions.spec.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.
Thanks for improving the publish options menu items test.
Looks great!
Hi @mdperez86, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
Ideally, the button would not react to clicking. We could also change the cursor to Surprisingly, the WP Figma library doesn't even have a disabled state. If this doesn't sit with us, I think we've used the secondary disabled state for primary buttons in the past. |
* Disable action buttons when product form is invalid * Move to trash action should be enabled when editing a product even when the form is invalid * Hide Move to trash action button in the Add new product page * Hide product link when the name field has any error * Disable Publish options menu button when all menu items are disabled * Test menu items by text instead of index
@jarekmorawski if there are more changes required, could we open a separate issue? This is to make sure no information is lost (due to e.g. PRs being closed). |
All Submissions:
Changes proposed in this Pull Request:
Closes 38-gh-woocommerce/mothra-private.
How to test the changes in this Pull Request:
3. If at least one field is invalid all action buttons should become disabled
4. When form fields are valid, action buttons disable behavior should remain in accordance with other requirements
5. When editing a product if the form is invalid then Move to trash action button should be enabled
6. When adding a new product `Move to trash` action button should not be shown
7. `Move to trash` is only visible when editing the product
8. When editing a product if the name field has any error then the product link is not shown but the error message does. See #issuecomment-1248104111 down below.
9. Publish options menu should be disabled if all menu items are disabled
Other information:
pnpm changelog add --filter=<project>
?FOR PR REVIEWER ONLY: