Skip to content

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

TypeScript

fix(FormLayout): stretch horizontal-labels controls below the 480px collapse (#7501)

Harjoth Kharab609ddbae451
diff --git a/.changeset/form-layout-horizontal-labels-collapse-stretch.md b/.changeset/form-layout-horizontal-labels-collapse-stretch.md
new file mode 100644
index 0000000000..188b0a1d4d
--- /dev/null
+++ b/.changeset/form-layout-horizontal-labels-collapse-stretch.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `FormLayout`: below the 480px collapse, `direction="horizontal-labels"` controls now fill the column the way they do in a vertical `FormLayout`. Previously each control shrank to its content, so a `Selector` was only as wide as its current value. The two-column layout above 480px is unchanged.
+
+@harjothkhara
diff --git a/.github/scripts/story-play-guard.js b/.github/scripts/story-play-guard.js
index 0c6d00f1f2..85525db744 100644
--- a/.github/scripts/story-play-guard.js
+++ b/.github/scripts/story-play-guard.js
@@ -194,6 +194,19 @@ const TARGETS = [
hasTouch: true,
},
]),
+ {
+ component: 'FormLayout (phone)',
+ story: 'core-formlayout--horizontal-labels',
+ viewport: {width: 390, height: 844},
+ guards:
+ 'below the 480px collapse, horizontal-labels controls fill the column, including a Selector with a short value',
+ },
+ {
+ component: 'FormLayout',
+ story: 'core-formlayout--horizontal-labels',
+ viewport: {width: 481, height: 844},
+ guards: 'just above the collapse, labels stay beside their controls',
+ },
{
component: 'TabList',
story: 'core-tablist--full-bleed-geometry',
diff --git a/apps/storybook/stories/FormLayout.stories.tsx b/apps/storybook/stories/FormLayout.stories.tsx
index ac418927d3..4aa064832b 100644
--- a/apps/storybook/stories/FormLayout.stories.tsx
+++ b/apps/storybook/stories/FormLayout.stories.tsx
@@ -2,6 +2,7 @@
import {useState} from 'react';
import type {Meta, StoryObj} from '@storybook/react';
+import {expect} from 'storybook/test';
import {FormLayout} from '@astryxdesign/core/FormLayout';
import {TextInput} from '@astryxdesign/core/TextInput';
import {Selector} from '@astryxdesign/core/Selector';
@@ -110,6 +111,31 @@ export const HorizontalLabels: Story = {
</FormLayout>
);
},
+ // Run by .github/scripts/story-play-guard.js at a phone and a 481px viewport.
+ play: async ({canvasElement}) => {
+ const layout = canvasElement.querySelector(
+ '[data-direction="horizontal-labels"]',
+ );
+ if (!layout) {
+ throw new Error('Expected a horizontal-labels FormLayout');
+ }
+ await expect(layout.children).toHaveLength(3);
+ const layoutWidth = layout.getBoundingClientRect().width;
+ const collapsed = window.matchMedia('(max-width: 480px)').matches;
+ // Each Field is display: contents, so its label wrapper and control
+ // wrapper are the layout's items.
+ for (const field of Array.from(layout.children)) {
+ const label = field.children[0].getBoundingClientRect();
+ const control = field.children[1].children[0].getBoundingClientRect();
+ if (collapsed) {
+ // Stacked: every control fills the column, whatever its value's width.
+ await expect(control.width).toBeCloseTo(layoutWidth, 0);
+ } else {
+ // Two columns: the label sits to the left of its control.
+ await expect(label.right).toBeLessThanOrEqual(control.left);
+ }
+ }
+ },
};
// ─── Mixed: Astryx inputs + Field-wrapped custom controls ─────────────────
diff --git a/packages/core/src/FormLayout/FormLayout.tsx b/packages/core/src/FormLayout/FormLayout.tsx
index 04c26e5cca..f710fc0dbc 100644
--- a/packages/core/src/FormLayout/FormLayout.tsx
+++ b/packages/core/src/FormLayout/FormLayout.tsx
@@ -60,6 +60,7 @@ const styles = stylex.create({
display: 'flex',
flexDirection: 'column',
gap: spacingVars['--spacing-4'],
+ alignItems: 'stretch',
},
},
});
diff --git a/packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snap b/packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snap
index 49649ffba3..6337fa12dc 100644
--- a/packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snap
+++ b/packages/core/src/FormLayout/__snapshots__/FormLayout.test.tsx.snap
@@ -17,7 +17,7 @@ exports[`FormLayout > matches snapshot for horizontal direction 1`] = `
exports[`FormLayout > matches snapshot for horizontal-labels direction 1`] = `
<div
- class="astryx-form-layout FormLayout__styles.base xdt5ytf FormLayout__styles.horizontalLabels xrvj5dj x1pmbctz xlaq8a2 x7a106z xedohl4 x1rpgqan x1a1jff"
+ class="astryx-form-layout FormLayout__styles.base xdt5ytf FormLayout__styles.horizontalLabels xrvj5dj x1pmbctz xlaq8a2 x7a106z xedohl4 x1rpgqan x1a1jff x1q32nj3"
data-direction="horizontal-labels"
data-testid="layout"
>