An open source design system that's fully customizable and agent ready
TypeScript
fix(core): center XDSSpinner in icon-only button loading state (#2905)
Cindy Zhang0e01e64df726
diff --git a/.changeset/icon-button-spinner-centering.md b/.changeset/icon-button-spinner-centering.mdnew file mode 100644index 0000000000..dd16ea20fe--- /dev/null+++ b/.changeset/icon-button-spinner-centering.md@@ -0,0 +1,5 @@+---+'@xds/core': patch+---++Fix `XDSSpinner` rendering off-center inside the icon-only `XDSButton` loading state. The spinner canvas now pins its CSS layout size to its logical dimensions instead of deriving it from the device pixel ratio, so it no longer overflows its `overflow: hidden` wrapper and clips asymmetrically at fractional device pixel ratios. The button loading overlay and the spinner wrapper also use `display: grid` + `place-items: center` for sub-pixel-stable centering.diff --git a/packages/core/src/Button/XDSButton.tsx b/packages/core/src/Button/XDSButton.tsxindex 405462a047..257b07b5a4 100644--- a/packages/core/src/Button/XDSButton.tsx+++ b/packages/core/src/Button/XDSButton.tsx@@ -393,9 +393,8 @@ const loadingStyles = stylex.create({left: 0,right: 0,bottom: 0,- display: 'flex',- alignItems: 'center',- justifyContent: 'center',+ display: 'grid',+ placeItems: 'center',},});diff --git a/packages/core/src/Spinner/XDSSpinner.tsx b/packages/core/src/Spinner/XDSSpinner.tsxindex 8ac73798f4..13a5f31ad6 100644--- a/packages/core/src/Spinner/XDSSpinner.tsx+++ b/packages/core/src/Spinner/XDSSpinner.tsx@@ -62,7 +62,8 @@ const styles = stylex.create({gap: spacingVars['--spacing-2'],},spinner: {- display: 'inline-block',+ display: 'inline-grid',+ placeItems: 'center',overflow: 'hidden',verticalAlign: 'middle',},@@ -200,12 +201,16 @@ export function XDSSpinner({? `${themeTokens['--color-on-dark']}4D`: themeTokens['--color-track'];- const radius = (diameter / 2) * pixelRatio;- const lineWidth = border * pixelRatio;- // Ensure even frame size so center is always on a whole pixel (prevents rotation jitter)- const rawFrameSize = Math.ceil((radius + lineWidth) * 2);+ const cssSize = diameter + border * 2;++ // Round to an even number of device pixels so the center stays on a whole+ // pixel (avoids rotation jitter); keep CSS size pinned to cssSize (#2732).+ const rawFrameSize = Math.round(cssSize * pixelRatio);const frameSize = rawFrameSize + (rawFrameSize % 2);- const cssSize = frameSize / pixelRatio;++ const scale = frameSize / cssSize;+ const radius = (diameter / 2) * scale;+ const lineWidth = border * scale;canvas.height = canvas.width = frameSize;canvas.style.width = canvas.style.height = cssSize + 'px';