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

Commit

Permalink
Mini Cart drawer: print width in PHP (#9329)
Browse files Browse the repository at this point in the history
* Mini Cart drawer: print width in PHP

* Remove unnecessary timeout

* Make sure classic themes have a Mini Cart contents width value set up
  • Loading branch information
Aljullu authored May 5, 2023
1 parent f42ff5f commit 58d721f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 2 additions & 0 deletions assets/js/base/components/drawer/style.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
:root {
/* This value might be overridden in PHP based on the attribute set by the user. */
--drawer-width: 480px;
--neg-drawer-width: calc(var(--drawer-width) * -1);
}

Expand Down
7 changes: 1 addition & 6 deletions assets/js/blocks/mini-cart/mini-cart-contents/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ type MiniCartContentsBlockProps = {
export const MiniCartContentsBlock = (
props: MiniCartContentsBlockProps
): JSX.Element => {
const {
children,
attributes: { width },
} = props;

document.documentElement.style.setProperty( '--drawer-width', width );
const { children } = props;

return <>{ children }</>;
};
3 changes: 3 additions & 0 deletions src/BlockTypes/MiniCartContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ protected function enqueue_assets( array $attributes ) {
);

$parsed_style = '';
if ( array_key_exists( 'width', $attributes ) ) {
$parsed_style .= ':root{--drawer-width: ' . esc_html( $attributes['width'] ) . '}';
}

foreach ( $styles as $style ) {
$selector = is_array( $style['selector'] ) ? implode( ',', $style['selector'] ) : $style['selector'];
Expand Down
2 changes: 0 additions & 2 deletions tests/e2e/specs/shopper/mini-cart.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,6 @@ describe( 'Shopper → Mini Cart', () => {
'.wc-block-components-quantity-selector__button--plus'
);

await page.waitForTimeout( 500 );

await page.click(
'.wc-block-components-quantity-selector__button--plus'
);
Expand Down

0 comments on commit 58d721f

Please sign in to comment.