-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add help tip for Product Image and Product Gallery meta boxes #35834
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
|
I feel that the jQuery implementation is not ideal, since you can see the tooltip showing up after the initial render. However, I couldn't find a good alternative using the Also, I added the tooltip text twice. Is there any way of improving that? |
Test Results SummaryCommit SHA: 24a87c4
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. |
mattsherman
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 start on this!
I left a few minor comments. Once the PR is out of Draft, just ping me and I'll review it again/officially!
Not a big deal, but I noticed that if you click "Set product image", select an image, and then remove that image, the tooltip after "Set product image" doesn't re-appear. If easy to fix, I'd do it. Otherwise, it's fine as is.
| 'i18n_product_other_tip' => __( 'Product types define available product details and attributes, such as downloadable files and variations. They’re also used for analytics and inventory management.', 'woocommerce' ), | ||
| 'i18n_product_description_tip' => __( 'Describe this product. What makes it unique? What are its most important features?', 'woocommerce' ), | ||
| 'i18n_product_short_description_tip' => __( 'Summarize this product in 1-2 short sentences. We’ll show it at the top of the page.', 'woocommerce' ), | ||
| 'i18n_product_image_tip' => __( 'For best results, upload JPEG or PNG files that are 1000 by 1000 pixels or larger. Maximum upload file size: 2GB.', 'woocommerce' ), |
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.
The max upload size is dynamic. Use:
size_format( wp_max_upload_size() )
| </div> | ||
| <p class="add_product_images hide-if-no-js"> | ||
| <a href="#" data-choose="<?php esc_attr_e( 'Add images to product gallery', 'woocommerce' ); ?>" data-update="<?php esc_attr_e( 'Add to gallery', 'woocommerce' ); ?>" data-delete="<?php esc_attr_e( 'Delete image', 'woocommerce' ); ?>" data-text="<?php esc_attr_e( 'Delete', 'woocommerce' ); ?>"><?php esc_html_e( 'Add product gallery images', 'woocommerce' ); ?></a> | ||
| <?php echo wc_help_tip( __('For best results, upload JPEG or PNG files that are 1000 by 1000 pixels or larger. Maximum upload file size: 2GB.', 'woocommerce' ) ) ?> |
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.
Can you use the i18n_product_image_tip in class-wc-admin-assets.php above?
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 don't know how to do that. Can you help me find a way?
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.
Ha, nevermind... 😄 I failed to notice that the i18n_product_image_tip was actually getting put into a JS script. Hmm... I guess the only ways to avoid this duplication would be to...
- move this out to a separate global that could be references by both
class-wc-admin-assets.phpand this php file, or - move the creation of this tooltip to JS as the other one is being done (though there is no other reason for it to be done in JS)
I don't hate option (2)... it brings a certain consistency to how they are both handled.
| .append( | ||
| '<span class="woocommerce-help-tip" tabindex="-1"></span>' | ||
| ) | ||
| .find( '.woocommerce-help-tip' ) |
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'm not a jQuery expert (I looked this up), but I think you could do...
$( '#set-post-thumbnail` ).after( '<span class="woocommerce-help-tip" tabindex="-1"></span>' )
That would be a little more clearer, I think.
| .attr( 'for', 'content' ) | ||
| .attr( | ||
| 'aria-label', | ||
| woocommerce_admin_meta_boxes.i18n_product_image_tip | ||
| ) |
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.
Any reason not to just include those in the initial markup for the span?
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 one. I copied the code from another place. I tested moving the attributes directly to the markup and it seems to work.
| $( this ).trigger( 'focus' ); | ||
| } ); | ||
|
|
||
| $( '#set-post-thumbnail' ) |
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.
Since the #set-post-thumbnail element is added via a filter, and thus could be altered by another plugin, we should account for that and handle the scenario where this element doesn't exist.
|
@mattsherman I'm also thinking that, even though I'm adding aria-label for the tooltip in jQuery, the one generated in PHP by |
|
@mattsherman Another thought: what if I add them both via jQuery? Since I was able to only add one of them via PHP. Might make the whole solution simpler. |
We definitely want the
I'm leaning heavily towards thinking this is best, especially if the |
mattsherman
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 iteration. I agree with you that perhaps you should just do both thumbnails in JS for consistency.
| 'i18n_product_other_tip' => __( 'Product types define available product details and attributes, such as downloadable files and variations. They’re also used for analytics and inventory management.', 'woocommerce' ), | ||
| 'i18n_product_description_tip' => __( 'Describe this product. What makes it unique? What are its most important features?', 'woocommerce' ), | ||
| 'i18n_product_short_description_tip' => __( 'Summarize this product in 1-2 short sentences. We’ll show it at the top of the page.', 'woocommerce' ), | ||
| /* translators: %s: maximum file size */ |
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.
%s should be %1$s
| <a href="#" data-choose="<?php esc_attr_e( 'Add images to product gallery', 'woocommerce' ); ?>" data-update="<?php esc_attr_e( 'Add to gallery', 'woocommerce' ); ?>" data-delete="<?php esc_attr_e( 'Delete image', 'woocommerce' ); ?>" data-text="<?php esc_attr_e( 'Delete', 'woocommerce' ); ?>"><?php esc_html_e( 'Add product gallery images', 'woocommerce' ); ?></a> | ||
| <?php echo wc_help_tip( sprintf( __( 'For best results, upload JPEG or PNG files that are 1000 by 1000 pixels or larger. Maximum upload file size: %1$s.', 'woocommerce' ), size_format( wp_max_upload_size() ) ) ); ?> | ||
| <?php | ||
| /* translators: %s: maximum file size */ |
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.
%s should be %1$s
| </div> | ||
| <p class="add_product_images hide-if-no-js"> | ||
| <a href="#" data-choose="<?php esc_attr_e( 'Add images to product gallery', 'woocommerce' ); ?>" data-update="<?php esc_attr_e( 'Add to gallery', 'woocommerce' ); ?>" data-delete="<?php esc_attr_e( 'Delete image', 'woocommerce' ); ?>" data-text="<?php esc_attr_e( 'Delete', 'woocommerce' ); ?>"><?php esc_html_e( 'Add product gallery images', 'woocommerce' ); ?></a> | ||
| <?php echo wc_help_tip( __('For best results, upload JPEG or PNG files that are 1000 by 1000 pixels or larger. Maximum upload file size: 2GB.', 'woocommerce' ) ) ?> |
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.
Ha, nevermind... 😄 I failed to notice that the i18n_product_image_tip was actually getting put into a JS script. Hmm... I guess the only ways to avoid this duplication would be to...
- move this out to a separate global that could be references by both
class-wc-admin-assets.phpand this php file, or - move the creation of this tooltip to JS as the other one is being done (though there is no other reason for it to be done in JS)
I don't hate option (2)... it brings a certain consistency to how they are both handled.
| setPostThumbnail | ||
| .after( | ||
| `<span class="woocommerce-help-tip" tabindex="-1" for="content" aria-label="${ woocommerce_admin_meta_boxes.i18n_product_image_tip }"></span>` | ||
| ) | ||
| .parent() | ||
| .find( '.woocommerce-help-tip' ) |
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.
The whole .parent().find() was bugging me, so I dug a bit...
you can do this instead...
$(
`<span class="woocommerce-help-tip" tabindex="-1" for="content" aria-label="${ woocommerce_admin_meta_boxes.i18n_product_image_tip }"></span>`
)
.insertAfter( setPostThumbnail )
.tipTip()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! that's better
Yeah, it's a little janky, but it doesn't seem too bad. To be honest, there is a lot of post-render re-layout going on in this page, so this is just a minor addition to existing problems (which we are addressing in the new product experience).
Well, you could load the string into a Though, it does seem to leave us without
I gave some thoughts on this in another comment I recently made (I had overlooked your initial questions). |
| if ( setPostThumbnail ) { | ||
| setPostThumbnail | ||
| .after( | ||
| `<span class="woocommerce-help-tip" tabindex="-1" for="content" aria-label="${ woocommerce_admin_meta_boxes.i18n_product_image_tip }"></span>` |
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.
Is for a valid attribute for a <span>?
I only see a reference to it being used on <label>.
Actually, since the aria-label is for the <span> itself, I don't think we need a for in any case...
The example of aria-label on MDN shows it being used on a <button> that does not have text content. That is the same case we have here.
Refactor jQuery code for simplicity
Refactor DOM manipulation code Remove PHP implementation
a3e9b45 to
21d926e
Compare
mattsherman
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 iteration on this, @nathanss ! I like the consistent approach you arrived at for both tooltips -- it's nice seeing less code and "duplication".
Tested and works well. Tried keyboard and VoiceOver and the tooltips were spoken when focused.
mattsherman
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 find on why the e2e tests were failing, and I agree that this new location for this code seems like a better fit.
Re-tested and things still work well.
Just left one comment requesting a comment be added to describe what is being done (as is the convention in the rest of the file).
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 work on this! Thanks for adding the comment
All Submissions:
Changes proposed in this Pull Request:
Adds a tooltip for both "Set product image" and "Add product gallery images" buttons
Closes #35017.
How to test the changes in this Pull Request:
Other information:
pnpm --filter=<project> changelog add?FOR PR REVIEWER ONLY: