Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Mini Cart: stop using Modal component #9345

Merged
merged 10 commits into from
May 16, 2023
Merged

Conversation

Aljullu
Copy link
Contributor

@Aljullu Aljullu commented May 4, 2023

This PR removes the usage of the Modal component from @wordpress/components. Instead, it updates our Drawer component to incorporate some functionality from Modal. I didn't copy & paste everything from the Modal component, instead, I just tried to import the features that were needed for our use case.

Fixes #8606.

Part of #8452.

Accessibility

Testing

User Facing Testing

This PR shouldn't introduce any visual changes for users, so testing it means making sure there are no regressions.

  1. Add the Mini Cart block to the header of your site via (Appearance > Editor).
  2. In the frontend and with the Cart empty, open the Mini Cart drawer, verify you can open and close the drawer without problems.
  3. Add some products to your cart and open the Mini Cart drawer again. Verify you can open and close it, you can change the products quantity, etc.
  4. Go to Appearance > Editor > Template Parts > Mini Cart and change some of the styles of the inner blocks. For example, add a custom background, border and width to the Mini Cart Contents block.
  5. Repeat step 3.

Now, let's test that things keep working if there are two Mini Cart blocks in the same page. We don't officially support it, but at the same time we don't want the experience to be broken.

  1. create a post or page and add the Mini Cart block.
  2. Open that post/page in the frontend. You should now have two Mini Cart buttons in the screen, the one from the site header and the one from the post/page.
  3. Verify both buttons work as expected.
  • Do not include in the Testing Notes

WooCommerce Visibility

  • WooCommerce Core
  • Feature plugin
  • Experimental

Changelog

Mini Cart block no longer uses the Modal component from @wordpress/components.

@Aljullu Aljullu added status: needs review type: bug The issue/PR concerns a confirmed bug. type: refactor The issue/PR is related to refactoring. block: mini-cart Issues related to the Mini-Cart block. labels May 4, 2023
@Aljullu Aljullu self-assigned this May 4, 2023
@woocommercebot woocommercebot requested review from a team and thealexandrelara and removed request for a team May 4, 2023 07:53
Comment on lines -77 to -85
array(
'selector' => '.wc-block-mini-cart__drawer .components-modal__header',
'properties' => array(
array(
'property' => 'color',
'value' => $text_color ? $text_color['value'] : false,
),
),
),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these styles weren't used anywhere, as we weren't setting a modal header.

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2023

The release ZIP for this PR is accessible via:

https://wcblocks.wpcomstaging.com/wp-content/uploads/woocommerce-gutenberg-products-block-9345.zip

Script Dependencies Report

The compare-assets action has detected some changed script dependencies between this branch and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Removed
reviews-frontend.js wc-settings, wp-a11y, wp-api-fetch, wp-compose, wp-element, wp-i18n, wp-is-shallow-equal, wp-polyfill ⚠️
active-filters-frontend.js wc-blocks-data-store, wc-price-format, wc-settings, wp-data, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-url ⚠️
all-products-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-polyfill, wp-primitives, wp-style-engine, wp-url, wp-warning, wp-wordcount ⚠️
cart-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-context, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-blocks, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-plugins, wp-polyfill, wp-primitives, wp-style-engine, wp-url, wp-warning, wp-wordcount ⚠️
checkout-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-blocks-shared-hocs, wc-price-format, wc-settings, wp-a11y, wp-api-fetch, wp-autop, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-plugins, wp-polyfill, wp-primitives, wp-url, wp-warning, wp-wordcount ⚠️
filter-wrapper-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-price-format, wc-settings, wp-a11y, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-style-engine, wp-url, wp-warning ⚠️
mini-cart-frontend.js wp-polyfill ⚠️
rating-filter-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-settings, wp-a11y, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-url, wp-warning ⚠️
mini-cart-component-frontend.js lodash, react, wc-blocks-checkout, wc-blocks-data-store, wc-blocks-registry, wc-price-format, wc-settings, wp-a11y, wp-autop, wp-compose, wp-data, wp-deprecated, wp-dom, wp-element, wp-hooks, wp-html-entities, wp-i18n, wp-is-shallow-equal, wp-keycodes, wp-polyfill, wp-primitives, wp-style-engine, wp-url, wp-warning, wp-wordcount ⚠️

This comment was automatically generated by the ./github/compare-assets action.

TypeScript Errors Report

  • Files with errors: 471
  • Total errors: 2268

🎉 🎉 This PR does not introduce new TS errors.

comments-aggregator

@include visually-hidden();
}
}
.admin-bar .wc-block-components-drawer__content {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been moved from here:

.admin-bar .wp-block-woocommerce-mini-cart-contents {
margin-top: 46px;
height: calc(100dvh - 46px);
}
@media only screen and (min-width: 783px) {
.admin-bar .wp-block-woocommerce-mini-cart-contents {
margin-top: 32px;
height: calc(100dvh - 32px);
}
}

@github-actions
Copy link
Contributor

github-actions bot commented May 4, 2023

Size Change: -27.3 kB (-2%)

Total Size: 1.08 MB

Filename Size Change
build/active-filters-frontend.js 8.57 kB +9 B (0%)
build/active-filters-wrapper--attribute-filter-wrapper--price-filter-wrapper--rating-filter-wrapper--stoc--78b62dd5-frontend.js 0 B -2.31 kB (removed) 🏆
build/active-filters-wrapper-frontend.js 7.62 kB +2.94 kB (+63%) 🆘
build/active-filters.js 7.48 kB -1 B (0%)
build/all-products-frontend.js 11.9 kB -196 B (-2%)
build/all-products.js 39.1 kB +63 B (0%)
build/all-reviews.js 7.77 kB +1 B (0%)
build/attribute-filter-frontend.js 0 B -23.2 kB (removed) 🏆
build/attribute-filter-wrapper--rating-filter-wrapper--stock-filter-wrapper-frontend.js 0 B -5.53 kB (removed) 🏆
build/attribute-filter-wrapper-frontend.js 4.28 kB -352 B (-8%)
build/attribute-filter.js 13.2 kB -114 B (-1%)
build/breadcrumbs.js 2.04 kB -1 B (0%)
build/cart-blocks/cart-accepted-payment-methods-frontend.js 1.39 kB +7 B (+1%)
build/cart-blocks/cart-cross-sells-products-frontend.js 3.73 kB -1.8 kB (-33%) 🎉
build/cart-blocks/cart-express-payment--checkout-blocks/express-payment-frontend.js 5.17 kB +6 B (0%)
build/cart-blocks/cart-items-frontend.js 301 B -1 B (0%)
build/cart-blocks/cart-line-items--mini-cart-contents-block/products-table-frontend.js 5.48 kB +91 B (+2%)
build/cart-blocks/cart-line-items-frontend.js 1.06 kB -2 B (0%)
build/cart-blocks/cart-order-summary-frontend.js 1.28 kB +1 B (0%)
build/cart-blocks/cart-totals-frontend.js 308 B +1 B (0%)
build/cart-blocks/empty-cart-frontend.js 345 B -1 B (0%)
build/cart-blocks/filled-cart-frontend.js 656 B +2 B (0%)
build/cart-blocks/order-summary-coupon-form-frontend.js 1.63 kB +1 B (0%)
build/cart-blocks/order-summary-discount-frontend.js 2.12 kB -1 B (0%)
build/cart-blocks/order-summary-heading-frontend.js 333 B +1 B (0%)
build/cart-blocks/order-summary-shipping-frontend.js 17 kB -29 B (0%)
build/cart-blocks/order-summary-taxes-frontend.js 435 B +1 B (0%)
build/cart-blocks/proceed-to-checkout-frontend.js 1.38 kB +1 B (0%)
build/cart-frontend.js 29.7 kB +42 B (0%)
build/cart.js 45 kB +235 B (+1%)
build/checkout-blocks/actions-frontend.js 1.85 kB +4 B (0%)
build/checkout-blocks/billing-address--checkout-blocks/shipping-address-frontend.js 4.7 kB -27 B (-1%)
build/checkout-blocks/billing-address-frontend.js 1.18 kB +2 B (0%)
build/checkout-blocks/contact-information-frontend.js 2.05 kB +2 B (0%)
build/checkout-blocks/fields-frontend.js 330 B -1 B (0%)
build/checkout-blocks/order-note-frontend.js 1.14 kB +4 B (0%)
build/checkout-blocks/order-summary-cart-items-frontend.js 3.69 kB -2 B (0%)
build/checkout-blocks/order-summary-discount-frontend.js 2.29 kB -4 B (0%)
build/checkout-blocks/order-summary-fee-frontend.js 276 B +1 B (0%)
build/checkout-blocks/order-summary-shipping-frontend.js 17 kB -19 B (0%)
build/checkout-blocks/payment-frontend.js 8.29 kB +12 B (0%)
build/checkout-blocks/pickup-options-frontend.js 4.8 kB -6 B (0%)
build/checkout-blocks/shipping-address-frontend.js 1.17 kB +2 B (0%)
build/checkout-blocks/shipping-method-frontend.js 2.59 kB -4 B (0%)
build/checkout-blocks/shipping-methods-frontend.js 6.36 kB +9 B (0%)
build/checkout-blocks/terms-frontend.js 1.56 kB +6 B (0%)
build/checkout-blocks/totals-frontend.js 312 B +2 B (+1%)
build/checkout-frontend.js 31.3 kB +24 B (0%)
build/checkout.js 46.3 kB +6 B (0%)
build/customer-account.js 3.18 kB -1 B (0%)
build/featured-category.js 15 kB +562 B (+4%)
build/featured-product.js 15.2 kB +517 B (+4%)
build/filter-wrapper-frontend.js 14.2 kB +68 B (0%)
build/filter-wrapper.js 2.39 kB -3 B (0%)
build/handpicked-products.js 8 kB -5 B (0%)
build/mini-cart-component-frontend.js 28.4 kB -652 B (-2%)
build/mini-cart-contents-block/cart-button-frontend.js 1.73 kB +867 B (+100%) 🆘
build/mini-cart-contents-block/checkout-button-frontend.js 1.74 kB +870 B (+100%) 🆘
build/mini-cart-contents-block/filled-cart-frontend.js 266 B -2 B (-1%)
build/mini-cart-contents-block/footer-frontend.js 4.1 kB +865 B (+27%) 🚨
build/mini-cart-contents-block/products-table-frontend.js 591 B +2 B (0%)
build/mini-cart-contents-block/shopping-button-frontend.js 528 B -232 B (-31%) 🎉
build/mini-cart-contents-block/title-frontend.js 1.91 kB +821 B (+76%) 🆘
build/mini-cart-contents-block/title-items-counter-frontend.js 1.61 kB +877 B (+120%) 🆘
build/mini-cart-contents-block/title-label-frontend.js 1.54 kB +878 B (+133%) 🆘
build/mini-cart-contents.js 18 kB +110 B (+1%)
build/mini-cart-frontend.js 2.15 kB -3 B (0%)
build/price-filter-frontend.js 0 B -14.5 kB (removed) 🏆
build/price-filter-wrapper-frontend.js 6.75 kB +974 B (+17%) ⚠️
build/price-filter.js 8.47 kB +4 B (0%)
build/product-add-to-cart--product-rating.js 0 B -151 B (removed) 🏆
build/product-add-to-cart-frontend.js 6.52 kB +18 B (0%)
build/product-add-to-cart.js 8.86 kB -17 B (0%)
build/product-best-sellers.js 8.34 kB -3 B (0%)
build/product-button--product-image--product-price--product-rating--product-sale-badge--product-sku--prod--408017d2.js 0 B -262 B (removed) 🏆
build/product-button--product-image--product-price--product-rating--product-sale-badge--product-sku--prod--5bce0384.js 963 B +500 B (+108%) 🆘
build/product-button-frontend.js 2.65 kB +736 B (+38%) 🚨
build/product-button.js 4.01 kB -169 B (-4%)
build/product-categories.js 2.37 kB +4 B (0%)
build/product-category.js 9.35 kB -4 B (0%)
build/product-image-frontend.js 2.63 kB +794 B (+43%) 🚨
build/product-image.js 4.18 kB -133 B (-3%)
build/product-new.js 8.35 kB +5 B (0%)
build/product-on-sale.js 8.68 kB +4 B (0%)
build/product-price-frontend.js 203 B -1.97 kB (-91%) 🏆
build/product-price.js 1.68 kB -51 B (-3%)
build/product-query.js 11.6 kB +2 B (0%)
build/product-rating-frontend.js 2.31 kB +857 B (+59%) 🆘
build/product-rating.js 999 B -39 B (-4%)
build/product-sale-badge-frontend.js 1.8 kB +828 B (+85%) 🆘
build/product-sale-badge.js 666 B -135 B (-17%) 👏
build/product-search.js 2.63 kB -2 B (0%)
build/product-sku-frontend.js 1.84 kB +838 B (+84%) 🆘
build/product-sku.js 535 B -44 B (-8%)
build/product-stock-indicator-frontend.js 2.02 kB +836 B (+70%) 🆘
build/product-stock-indicator.js 730 B -41 B (-5%)
build/product-summary-frontend.js 2.19 kB +896 B (+69%) 🆘
build/product-summary.js 904 B -18 B (-2%)
build/product-tag.js 8.97 kB -4 B (0%)
build/product-title-frontend.js 2.22 kB +855 B (+63%) 🆘
build/product-title.js 3.69 kB -57 B (-2%)
build/product-top-rated.js 8.58 kB -3 B (0%)
build/products-by-attribute.js 9.7 kB -3 B (0%)
build/rating-filter-frontend.js 21.3 kB -156 B (-1%)
build/rating-filter-wrapper-frontend.js 6.21 kB +3.17 kB (+104%) 🆘
build/rating-filter.js 6.89 kB -126 B (-2%)
build/reviews-by-category.js 12.1 kB +3 B (0%)
build/reviews-frontend.js 7.11 kB +7 B (0%)
build/single-product.js 11.1 kB -35 B (0%)
build/stock-filter-frontend.js 0 B -21.8 kB (removed) 🏆
build/stock-filter-wrapper-frontend.js 2.98 kB -338 B (-10%) 👏
build/stock-filter.js 7.61 kB -125 B (-2%)
build/store-notices.js 1.69 kB +4 B (0%)
build/vendors--attribute-filter-wrapper--cart-blocks/order-summary-coupon-form--cart-blocks/order-summary--48e1e4bb-frontend.js 6.82 kB -4 B (0%)
build/vendors--attribute-filter-wrapper--cart-blocks/order-summary-shipping--checkout-blocks/billing-addr--d9f38f9d-frontend.js 4.21 kB +15 B (0%)
build/vendors--cart-blocks/cart-cross-sells-products--cart-blocks/cart-line-items--cart-blocks/cart-order--3c5fe802-frontend.js 5.26 kB +1 B (0%)
build/vendors--cart-blocks/cart-line-items--checkout-blocks/order-summary-cart-items--mini-cart-contents---233ab542-frontend.js 3.57 kB -1 B (0%)
build/vendors--cart-blocks/order-summary-shipping--checkout-blocks/billing-address--checkout-blocks/order--decc3dc6-frontend.js 19.4 kB +11 B (0%)
build/vendors--checkout-blocks/shipping-method-frontend.js 12.5 kB +10 B (0%)
build/vendors--product-add-to-cart-frontend.js 7.26 kB +4 B (0%)
build/wc-blocks-editor-style-rtl.css 5.95 kB +18 B (0%)
build/wc-blocks-editor-style.css 5.94 kB +18 B (0%)
build/wc-blocks-style-rtl.css 27.8 kB +141 B (+1%)
build/wc-blocks-style.css 27.8 kB +138 B (0%)
build/wc-blocks-vendors.js 65 kB -113 B (0%)
build/wc-blocks.js 2.63 kB +3 B (0%)
build/attribute-filter-wrapper--stock-filter-wrapper-frontend.js 4.05 kB +4.05 kB (new file) 🆕
build/cart-blocks/cart-cross-sells-products--product-price-frontend.js 2.94 kB +2.94 kB (new file) 🆕
build/product-add-to-cart--product-button--product-image--product-rating--product-title.js 151 B +151 B (new file) 🆕
build/product-collection.js 2.99 kB +2.99 kB (new file) 🆕
build/product-template.js 3.28 kB +3.28 kB (new file) 🆕
build/vendors--attribute-filter-wrapper--stock-filter-wrapper-frontend.js 5.11 kB +5.11 kB (new file) 🆕
build/vendors--price-filter-wrapper-frontend.js 2.2 kB +2.2 kB (new file) 🆕
build/vendors--rating-filter-wrapper-frontend.js 5.11 kB +5.11 kB (new file) 🆕
ℹ️ View Unchanged
Filename Size
build/blocks-checkout.js 35.1 kB
build/cart-blocks/cart-cross-sells-frontend.js 253 B
build/cart-blocks/cart-express-payment-frontend.js 717 B
build/cart-blocks/order-summary-fee-frontend.js 273 B
build/cart-blocks/order-summary-subtotal-frontend.js 273 B
build/catalog-sorting.js 1.7 kB
build/checkout-blocks/express-payment-frontend.js 1.13 kB
build/checkout-blocks/order-summary-coupon-form-frontend.js 1.79 kB
build/checkout-blocks/order-summary-frontend.js 1.28 kB
build/checkout-blocks/order-summary-subtotal-frontend.js 273 B
build/checkout-blocks/order-summary-taxes-frontend.js 435 B
build/general-style-rtl.css 1.31 kB
build/general-style.css 1.31 kB
build/legacy-template.js 6.33 kB
build/mini-cart-contents-block/empty-cart-frontend.js 360 B
build/mini-cart-contents-block/items-frontend.js 237 B
build/mini-cart.js 4.2 kB
build/price-format.js 1.19 kB
build/product-add-to-cart--product-button--product-image--product-price--product-rating--product-sale-bad--49d3ecb2.js 251 B
build/product-results-count.js 1.66 kB
build/reviews-by-product.js 13.2 kB
build/vendors--checkout-blocks/pickup-options--checkout-blocks/shipping-methods-frontend.js 8.25 kB
build/wc-blocks-data.js 22.5 kB
build/wc-blocks-google-analytics.js 1.56 kB
build/wc-blocks-middleware.js 933 B
build/wc-blocks-registry.js 3.15 kB
build/wc-blocks-shared-context.js 1.52 kB
build/wc-blocks-shared-hocs.js 1.75 kB
build/wc-blocks-vendors-style-rtl.css 1.96 kB
build/wc-blocks-vendors-style.css 1.96 kB
build/wc-payment-method-bacs.js 816 B
build/wc-payment-method-cheque.js 811 B
build/wc-payment-method-cod.js 909 B
build/wc-payment-method-paypal.js 837 B
build/wc-settings.js 2.6 kB
build/wc-shipping-method-pickup-location.js 30.3 kB
build/woo-directives-runtime.js 2.73 kB
build/woo-directives-vendors.js 7.91 kB

compressed-size-action

Copy link
Contributor

@thealexandrelara thealexandrelara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ I have no complaints about the code
✅ I can open and close the Mini Cart drawer when the cart is empty
✅ I can open and close the Mini Cart drawer when the cart has products
✅ I can customize the styles for the Mini Cart (adding custom backgrounds, border, and/or changing the width)
✅ I can add multiple Mini Cart drawers and they work together

⚠️ When I open the Mini Cart drawer, the Close button appears always in a "focus" state which I think is valid from an accessibility point of view, but just want to confirm if the style is correct and we should, by default, show the "blue border" around the Close button.

image

⛔ When you decrease an specific item quantity from 2 to 1 (it looks like it only happens between these quantities) by clicking on the decrease button for this item, the drawer does not close when you click outside its area. The only way I managed to close it (besides using the Close button) was to give a click inside the drawer area followed by a click outside it as in this video:

Screen.Recording.2023-05-10.at.17.58.31.mov

@Aljullu Aljullu force-pushed the fix/mini-cart-drawer-component branch from b3f8637 to 988b797 Compare May 11, 2023 11:35
@Aljullu
Copy link
Contributor Author

Aljullu commented May 11, 2023

⚠️ When I open the Mini Cart drawer, the Close button appears always in a "focus" state which I think is valid from an accessibility point of view, but just want to confirm if the style is correct and we should, by default, show the "blue border" around the Close button.

Good point. In bf1f53c I added some styles to reset the default :focus styles if the close button doesn't match the :focus-visible pseudo-class. In my testing it seems to work well: opening the drawer with the keyboard shows the focus styles, but opening it with the mouse doesn't until the close button is focused again.

Could you test it and see if it looks good to you? 🙏

⛔ When you decrease an specific item quantity from 2 to 1 (it looks like it only happens between these quantities) by clicking on the decrease button for this item, the drawer does not close when you click outside its area. The only way I managed to close it (besides using the Close button) was to give a click inside the drawer area followed by a click outside it as in this video:

Good catch! That was a super confusing one, and I still don't understand what's going on. When the - button gets disabled, the focus returns to the <body>, which causes the drawer to close (in Firefox) or the drawer not possible to close clicking outside (Chrome). I don't know why the focus is lost, though, as I tried different approaches (setting a key, debouncing the disabled state...) and none of them worked. What's even more confusing is that if I remove the text input field, the issue gets fixed magically. 😕

In the end, I decided for not setting the disabled attribute and instead simulate it via tabIndex, aria-hidden and CSS. You can see it here: 988b797. I'm not very happy with it because it's a work-around instead of a real fix, but during my testing it performed well and I couldn't find any other solutions.

@Aljullu Aljullu force-pushed the fix/mini-cart-drawer-component branch from 988b797 to 351a216 Compare May 11, 2023 15:26
Copy link
Contributor

@thealexandrelara thealexandrelara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job, thank you for addressing the issues, now I can confirm that it is working well. I imagine how difficult it was to debug and find a solution for this, I'm glad that you find a way to solve it 🙌

I'm approving this PR since it is working as expected, but maybe a suggestion that I don't know if you tried is to keep a reference to the modal and when clicking on the QuantitySelector, you set the focus back to the modal, something like this:


// on Mini Cart
const modalRef = React.useRef();

<Drawer ref={modalRef} />

// on QuantitySelector if we find a way to send the modal reference or maybe to call a callback inside the onClick for the decrease button

<button 
  ...
  onClick={ () => {
    ...
    modalRef.current.focus(); // or a callback that calls the focus() method
  }}
/>

@Aljullu Aljullu force-pushed the fix/mini-cart-drawer-component branch from 351a216 to 4d75aa3 Compare May 12, 2023 10:12
@Aljullu
Copy link
Contributor Author

Aljullu commented May 12, 2023

I'm approving this PR since it is working as expected, but maybe a suggestion that I don't know if you tried is to keep a reference to the modal and when clicking on the QuantitySelector, you set the focus back to the modal, something like this:

Oh, that's a good idea! I reverted my previous work-around in 2274917 and implemented your suggestion in 4d75aa3. I changed it a bit so instead of moving the focus to the drawer, we move it to the text input field. This keeps the code cleaner and from an accessibility point of view I think it's better because it moves the focus closer to the previous position.

Thanks so much for the suggestion, @thealexandrelara! Would you mind taking another look?

@thealexandrelara
Copy link
Contributor

Thank you for implementing the suggestion 🙌 . I was testing it again, and it looks like the issue is still happening on Chrome (I'm using version 113.0.5672.92)

Screen.Recording.2023-05-12.at.16.21.23.mov

I tested on Firefox and Safari and the drawer closes when clicking outside it 🤔

@Aljullu
Copy link
Contributor Author

Aljullu commented May 15, 2023

Thanks for the review, @thealexandrelara, and good catch with that issue. Honestly, I don't know why that's happening, for some reason, Chrome is moving the focus to <body> even before useLayoutEffect() runs. 😕

I solved it by adding a check to see whether the focus is in the <body> element: 137770b. I also pushed a commit which adds a comment explaining that part of the code for future reference: 7f59f05.

Copy link
Contributor

@thealexandrelara thealexandrelara left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thank you for your hard work on this one, just tested and it is working as expected 🙌. LGTM! 🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
block: mini-cart Issues related to the Mini-Cart block. type: bug The issue/PR concerns a confirmed bug. type: refactor The issue/PR is related to refactoring.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mini Cart Block: Move away from using Modal component
2 participants