Commit 170d55f45d7 for woocommerce
commit 170d55f45d7a5acfdef80bdacc0eebc5d4a875df
Author: Tom Cafferkey <tjcafferkey@gmail.com>
Date: Fri Nov 20 11:08:43 2026 +0000
Cart and checkout block buttons to use global styles (#71096)
* Fix Cart and Checkout global button style inheritance
* Add changelog entry for global button style inheritance
* Fix checkout button typography inheritance in classic themes
* Classic theme buttons
* Remove unnecessary unit tests
* Remove unnecessary e2e tests
* Notice button fix
* Allow text override
diff --git a/plugins/woocommerce/changelog/fix-cart-checkout-global-button-styles b/plugins/woocommerce/changelog/fix-cart-checkout-global-button-styles
new file mode 100644
index 00000000000..58de326fb3d
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-cart-checkout-global-button-styles
@@ -0,0 +1,4 @@
+Significance: minor
+Type: fix
+
+Let Cart and Checkout buttons follow the theme's global button styles, including spacing and interaction states.
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/button/index.tsx b/plugins/woocommerce/client/blocks/assets/js/base/components/button/index.tsx
index 5f1d01029a7..3fd528a77c1 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/button/index.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/button/index.tsx
@@ -4,15 +4,16 @@
import { Button as AriakitButton } from '@ariakit/react';
import { forwardRef } from '@wordpress/element';
import clsx from 'clsx';
-import type { ForwardedRef } from 'react';
+import type { ForwardedRef, ReactNode } from 'react';
import type { ButtonProps as AriakitButtonProps } from '@ariakit/react';
/**
* Internal dependencies
*/
+import withGlobalStyles from './with-global-styles';
import './style.scss';
-type WCButtonProps = AriakitButtonProps & { children?: React.ReactNode };
+type WCButtonProps = AriakitButtonProps & { children?: ReactNode };
export interface ButtonProps extends WCButtonProps {
/**
@@ -57,12 +58,13 @@ const Button = forwardRef< HTMLButtonElement, ButtonProps | LinkProps >(
const buttonClassName = clsx(
'wc-block-components-button',
'wp-element-button',
+ 'wp-block-button__link',
className,
variant
);
if ( 'href' in props ) {
- return (
+ return withGlobalStyles(
<AriakitButton
render={
<a
@@ -88,7 +90,7 @@ const Button = forwardRef< HTMLButtonElement, ButtonProps | LinkProps >(
</div>
);
- return (
+ return withGlobalStyles(
<AriakitButton
ref={ ref }
className={ buttonClassName }
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/button/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/button/style.scss
index abd7b63ae02..2920e0f753a 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/button/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/button/style.scss
@@ -1,36 +1,10 @@
-// Cart and Checkout buttons use the same corners as their fields and panels. The rule has no specificity, so a button
-// radius from the theme (`styles.elements.button.border.radius`) still applies.
-:where(.wp-block-woocommerce-cart, .wp-block-woocommerce-checkout) :where(.wc-block-components-button:not(.is-link)) {
- border-radius: $universal-border-radius;
-}
-
-.wc-block-components-button:not(.is-link) {
- align-items: center;
- display: inline-flex;
- height: auto;
- justify-content: center;
- text-align: center;
- position: relative;
- transition: box-shadow 0.1s linear;
-
+@mixin button-appearance {
&:focus {
box-shadow: 0 0 0 2px $studio-blue;
box-shadow: inset 0 0 0 1px $white, 0 0 0 2px $studio-blue;
outline: 3px solid transparent;
}
- .wc-block-components-button__text {
- display: block;
-
- // Prevent runts/widows. Overwrite `balance` with `pretty`, as `pretty` is not supported in all browsers.
- text-wrap: balance;
- text-wrap: pretty;
-
- > svg {
- fill: currentColor;
- }
- }
-
&.text {
color: $gray-900;
@@ -39,15 +13,6 @@
}
}
- // Fade the whole button, not just its label, so the fill and border read as
- // unavailable too. Some buttons stay focusable and use aria-disabled rather
- // than the disabled attribute, so both need covering.
- &:disabled,
- &[aria-disabled="true"] {
- cursor: not-allowed;
- opacity: 0.5;
- }
-
&.outlined,
&.is-style-outline {
background: transparent;
@@ -70,8 +35,47 @@
}
}
+.wc-block-components-button:not(.is-link) {
+ align-items: center;
+ display: inline-flex;
+ height: auto;
+ justify-content: center;
+ position: relative;
+ transition: box-shadow 0.1s linear;
+
+ &:not(:where(.wp-block-woocommerce-cart *, .wp-block-woocommerce-checkout *)) {
+ @include button-appearance;
+ text-align: center;
+ }
+
+ .wc-block-components-button__text {
+ display: block;
+
+ // Prevent runts/widows. Overwrite `balance` with `pretty`, as `pretty` is not supported in all browsers.
+ text-wrap: balance;
+ text-wrap: pretty;
+
+ > svg {
+ fill: currentColor;
+ }
+ }
+
+ // Some disabled buttons remain focusable and use aria-disabled.
+ &:disabled,
+ &[aria-disabled="true"] {
+ cursor: not-allowed;
+ opacity: 0.5;
+ }
+}
+
+:where(.wp-block-woocommerce-cart, .wp-block-woocommerce-checkout) {
+ .wc-block-components-button:not(.is-link) .wc-block-components-button__text {
+ width: 100%;
+ }
+}
+
body:not(.woocommerce-block-theme-has-button-styles)
- .wc-block-components-button:not(.is-link) {
+ .wc-block-components-button:not(.is-link):not(:where(.wp-block-woocommerce-cart *, .wp-block-woocommerce-checkout *)) {
min-height: 3em;
&:focus {
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/button/with-global-styles.tsx b/plugins/woocommerce/client/blocks/assets/js/base/components/button/with-global-styles.tsx
new file mode 100644
index 00000000000..14b61d055e1
--- /dev/null
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/button/with-global-styles.tsx
@@ -0,0 +1,15 @@
+/**
+ * External dependencies
+ */
+import type { ReactElement } from 'react';
+
+/**
+ * Match core Button selectors without adding a layout box around flex or grid items.
+ */
+const withGlobalStyles = ( button: ReactElement ) => (
+ <div className="wp-block-button" style={ { display: 'contents' } }>
+ { button }
+ </div>
+);
+
+export default withGlobalStyles;
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/place-order-button/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/place-order-button/style.scss
index 9077250f191..3dd169d135d 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/place-order-button/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/place-order-button/style.scss
@@ -23,8 +23,9 @@
}
.wc-block-components-checkout-place-order-button__text {
- display: flex;
+ display: inline-flex;
align-items: center;
+ vertical-align: top;
}
.wc-block-components-checkout-place-order-button__separator {
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/totals/coupon/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/totals/coupon/style.scss
index e0efa874a4c..941c3ffe405 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/totals/coupon/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/cart-checkout/totals/coupon/style.scss
@@ -29,12 +29,7 @@
flex: 3 1 120px;
}
- // The button is at least as tall as the text input next to it (50px), whatever padding the theme gives buttons.
.wc-block-components-totals-coupon__button {
- min-block-size: 50px;
- padding-block: 0;
- padding-left: $gap;
- padding-right: $gap;
white-space: nowrap;
flex: 1 1 auto;
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/index.tsx b/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/index.tsx
index 0f81847a9fa..7fec997e333 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/index.tsx
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/index.tsx
@@ -4,13 +4,13 @@
import clsx from 'clsx';
import { __ } from '@wordpress/i18n';
import { Icon, close } from '@wordpress/icons';
+import { Button } from '@ariakit/react';
/**
* Internal dependencies
*/
import './style.scss';
import { getDefaultPoliteness, getStatusIcon } from './utils';
-import Button from '../button';
import { useSpokenMessage } from '../../hooks';
export interface NoticeBannerProps {
@@ -80,10 +80,9 @@ const NoticeBanner = ( {
</div>
{ !! isDismissible && (
<Button
- className="wc-block-components-notice-banner__dismiss"
+ className="wc-block-components-button wc-block-components-notice-banner__dismiss contained"
aria-label={ __( 'Dismiss this notice', 'woocommerce' ) }
onClick={ dismiss }
- removeTextWrap
>
<Icon icon={ close } />
</Button>
diff --git a/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/style.scss b/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/style.scss
index 8ea922adb1f..973be039abf 100644
--- a/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/base/components/notice-banner/style.scss
@@ -88,6 +88,7 @@
}
> .wc-block-components-button {
+ cursor: pointer;
margin: 6px 0 0 auto !important;
background: transparent none !important;
box-shadow: none !important;
diff --git a/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/style.scss b/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/style.scss
index 8d65fcc4a31..08d1e912763 100644
--- a/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/style.scss
+++ b/plugins/woocommerce/client/blocks/assets/js/blocks/checkout/inner-blocks/checkout-actions-block/style.scss
@@ -11,13 +11,16 @@ $place-order-column-width: max(50%, 260px);
}
.wc-block-checkout__actions_row {
- @include font-small-locked;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
gap: $gap-small;
+ .wc-block-components-checkout-return-to-cart-button {
+ @include font-small-locked;
+ }
+
.wc-block-components-checkout-place-order-button--full-width {
width: 100%;
}
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Cart.php b/plugins/woocommerce/src/Blocks/BlockTypes/Cart.php
index d060171d6b1..30adf5548e2 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Cart.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Cart.php
@@ -107,7 +107,7 @@ class Cart extends AbstractBlock {
* @return string[]
*/
protected function get_block_type_style() {
- return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style' ] );
+ return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style', 'wp-block-button' ] );
}
/**
diff --git a/plugins/woocommerce/src/Blocks/BlockTypes/Checkout.php b/plugins/woocommerce/src/Blocks/BlockTypes/Checkout.php
index e16583e1665..148fdfdcbfb 100644
--- a/plugins/woocommerce/src/Blocks/BlockTypes/Checkout.php
+++ b/plugins/woocommerce/src/Blocks/BlockTypes/Checkout.php
@@ -194,7 +194,7 @@ class Checkout extends AbstractBlock {
* @return string[]
*/
protected function get_block_type_style() {
- return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style' ] );
+ return array_merge( parent::get_block_type_style(), [ 'wc-blocks-packages-style', 'wp-block-button' ] );
}
/**