Mini-cart buttons: add explanation regarding why we need to check for children (https://github.com/woocommerce/woocommerce-blocks/pull/8847)

* Add comment explanation regarding the children buttons

* Update comment

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>

---------

Co-authored-by: Albert Juhé Lluveras <contact@albertjuhe.com>
This commit is contained in:
Alba Rincón 2023-03-24 16:25:09 +01:00 committed by GitHub
parent 2662cf09bd
commit 91eb482e17
1 changed files with 6 additions and 0 deletions

View File

@ -37,6 +37,9 @@ interface Props {
checkoutButtonLabel: string;
}
/**
* Checks if there are any children that are blocks.
*/
const hasChildren = ( children ): boolean => {
return children.some( ( child ) => {
if ( Array.isArray( child ) ) {
@ -58,6 +61,9 @@ const Block = ( {
parseInt( cartTotals.total_items_tax, 10 )
: parseInt( cartTotals.total_items, 10 );
// The `Cart` and `Checkout` buttons were converted to inner blocks, but we still need to render the buttons
// for themes that have the old `mini-cart.html` template. So we check if there are any inner blocks (buttons) and
// if not, render the buttons.
const hasButtons = hasChildren( children );
return (