Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Spinner): stop a narrow flex host compressing the spinner's box (#5484)

freddymetaa0d21c18c45f
diff --git a/.changeset/spinner-box-flex-shrink.md b/.changeset/spinner-box-flex-shrink.md
new file mode 100644
index 0000000000..bcfa632678
--- /dev/null
+++ b/.changeset/spinner-box-flex-shrink.md
@@ -0,0 +1,11 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Spinner: a narrow flex host no longer compresses the box and clips the ring (#5484)
+
+The spinner's box carried `overflow: hidden` from the canvas ring it no longer draws. It clipped nothing — the painted circle is inscribed in the box, so hiding or showing the overflow renders the same pixels at every size and shade — but a flex item whose overflow is not `visible` has an automatic minimum size of zero. That left the box with no floor: a flex host narrower than the spinner compressed it while the ring kept drawing at the size its own attributes ask for, and the clip then cut the ring off at the box edge, silently, because a sliced ring still spins.
+
+Ordinary layouts reached it. A `md` spinner beside a label in a 140px row rendered a 16px box around a 20px ring; an `lg` spinner next to a `flex: 1 0 100px` sibling lost half of its ring. The clip is gone and the box is `flex-shrink: 0`, so the box and the ring stay one measurement and a spinner that does not fit overflows its host visibly instead. Nothing moves for a spinner whose host already fitted it.
+
+@freddymeta
diff --git a/apps/storybook/stories/Spinner.stories.tsx b/apps/storybook/stories/Spinner.stories.tsx
index e4e8fb263c..5d147b318e 100644
--- a/apps/storybook/stories/Spinner.stories.tsx
+++ b/apps/storybook/stories/Spinner.stories.tsx
@@ -1,5 +1,6 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
+import type {CSSProperties} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
import {Spinner} from '@astryxdesign/core/Spinner';
import {Text} from '@astryxdesign/core/Text';
@@ -27,6 +28,20 @@ const meta: Meta<typeof Spinner> = {
export default meta;
type Story = StoryObj<typeof Spinner>;
+/**
+ * A flex host of a fixed width, drawn so the spinner's relationship to it is
+ * visible. Deliberately a raw flex container: the point of the story below is
+ * what an arbitrary consumer's layout does to the spinner's box.
+ */
+const narrowHost = (width: number): CSSProperties => ({
+ display: 'flex',
+ alignItems: 'center',
+ gap: 8,
+ width,
+ border: '1px dashed #b0b0b0',
+ padding: 4,
+});
+
export const Default: Story = {
args: {
size: 'md',
@@ -208,3 +223,49 @@ export const ThemedHairlineStroke: Story = {
</VStack>
),
};
+
+/**
+ * A flex host narrower than the spinner in it. The box keeps the ring's size
+ * and overflows the host visibly; before the fix the host compressed the box
+ * and the ring was cut off at its edge, silently — a sliced ring still spins,
+ * so nothing reported a problem. The dashed rule is the host, drawn so the
+ * overflow is legible.
+ *
+ * All three are ordinary layouts rather than contrived ones: a label beside a
+ * spinner in a narrow row, a spinner next to a sibling that will not give up
+ * its width, and a host smaller than the spinner outright.
+ */
+export const NarrowFlexHost: Story = {
+ render: () => (
+ <VStack gap={4} hAlign="start">
+ <VStack gap={1} hAlign="start">
+ <Text type="supporting" color="secondary">
+ Label beside it, in a 140px row
+ </Text>
+ <div style={narrowHost(140)}>
+ <Spinner size="md" />
+ <Text type="body">Uploading attachments…</Text>
+ </div>
+ </VStack>
+
+ <VStack gap={1} hAlign="start">
+ <Text type="supporting" color="secondary">
+ Beside a sibling that keeps its width (flex: 1 0 100px)
+ </Text>
+ <div style={narrowHost(120)}>
+ <Spinner size="lg" />
+ <div style={{flex: '1 0 100px', height: 8, background: '#e0e0e0'}} />
+ </div>
+ </VStack>
+
+ <VStack gap={1} hAlign="start">
+ <Text type="supporting" color="secondary">
+ Host narrower than the spinner outright (16px)
+ </Text>
+ <div style={narrowHost(16)}>
+ <Spinner size="xl" />
+ </div>
+ </VStack>
+ </VStack>
+ ),
+};
diff --git a/packages/core/src/Spinner/Spinner.tsx b/packages/core/src/Spinner/Spinner.tsx
index 04ef975352..dac93b8a70 100644
--- a/packages/core/src/Spinner/Spinner.tsx
+++ b/packages/core/src/Spinner/Spinner.tsx
@@ -226,7 +226,6 @@ const styles = stylex.create({
spinner: {
display: 'inline-grid',
placeItems: 'center',
- overflow: 'hidden',
verticalAlign: 'middle',
// The public geometry vars, resolved into the registered `<length>` pair
// the arithmetic below needs. Reading them here rather than in each
@@ -241,6 +240,27 @@ const styles = stylex.create({
// an inline style to a rule, which would hand a caller's `style={{width}}`
// a precedence over the box that it has never had.
[BOX_SIZE]: `calc(var(${RESOLVED_DIAMETER}) + var(${RESOLVED_STROKE}) * 2)`,
+
+ // The box is the ring's size, and a host does not get to take that away.
+ //
+ // `overflow: hidden` used to sit here, carried over from the canvas ring
+ // this component no longer draws. It clipped nothing — the painted circle
+ // is inscribed in the box, so hiding and showing the overflow render
+ // byte-identical pixels at every size, every shade, the labelled case and
+ // every rotation angle. What it did do is remove the floor under this box:
+ // a flex item whose overflow is not `visible` has an automatic minimum
+ // size of zero, so a narrow flex host was free to compress the box while
+ // the ring kept drawing at the size its own attributes ask for, and then
+ // the clip cut the ring off at the box edge. Ordinary rows hit it — a
+ // spinner beside a label in a 140px row lost 4px of its ring, one beside a
+ // `flex: 1 0 100px` sibling lost half of it — with nothing reporting a
+ // problem, because a sliced ring still spins.
+ //
+ // `flex-shrink: 0` then states the invariant directly rather than leaving
+ // it to the automatic minimum size, which a host takes away again the
+ // moment it sets `min-width: 0` on its items. A spinner that does not fit
+ // overflows its host visibly instead of being silently sliced.
+ flexShrink: 0,
},
ring: {
backfaceVisibility: 'hidden',