An open source design system that's fully customizable and agent ready
TypeScript
fix(GridSpan): keep long content such as a Tokenizer token in its column (#7528)
David Billiotc35e7ac4c5c9
diff --git a/.changeset/grid-span-min-content-overflow.md b/.changeset/grid-span-min-content-overflow.mdnew file mode 100644index 0000000000..a4f32cade2--- /dev/null+++ b/.changeset/grid-span-min-content-overflow.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] `GridSpan` keeps its content inside the span. A child whose min-content width is wider than the span, such as a `Tokenizer` with a long token, used to stretch the span's column past the grid cell; it now gets the span's width and truncates the way it does outside a Grid (#7438)++@WeAreResiliencediff --git a/.github/scripts/story-play-guard.js b/.github/scripts/story-play-guard.jsindex c889e3f40f..dac31e195b 100644--- a/.github/scripts/story-play-guard.js+++ b/.github/scripts/story-play-guard.js@@ -260,6 +260,12 @@ const TARGETS = [viewport: {width: 481, height: 844},guards: 'just above the collapse, labels stay beside their controls',},+ {+ component: 'Grid',+ story: 'core-grid--grid-span-with-long-content',+ guards:+ 'a full-width GridSpan holding a Tokenizer with a long token stays within its 500px host',+ },{component: 'TabList',story: 'core-tablist--full-bleed-geometry',diff --git a/apps/storybook/stories/Grid.stories.tsx b/apps/storybook/stories/Grid.stories.tsxindex 9975e878f5..f21538f4d7 100644--- a/apps/storybook/stories/Grid.stories.tsx+++ b/apps/storybook/stories/Grid.stories.tsx@@ -1,12 +1,15 @@// Copyright (c) Meta Platforms, Inc. and affiliates.import type {Meta, StoryObj} from '@storybook/react';+import {expect} from 'storybook/test';import * as stylex from '@stylexjs/stylex';import {Grid, GridSpan} from '@astryxdesign/core/Grid';import {Card} from '@astryxdesign/core/Card';import {Section} from '@astryxdesign/core/Section';import {Text} from '@astryxdesign/core/Text';import {VStack} from '@astryxdesign/core/Stack';+import {Tokenizer} from '@astryxdesign/core/Tokenizer';+import type {SearchableItem} from '@astryxdesign/core/Typeahead';import {colorVars,spacingVars,@@ -46,6 +49,11 @@ const styles = stylex.create({sectionLabel: {marginBlockEnd: spacingVars['--spacing-2'],},+ narrowHost: {+ maxWidth: 500,+ minWidth: 0,+ outline: `1px dashed ${colorVars['--color-border-emphasized']}`,+ },});const meta: Meta<typeof Grid> = {@@ -296,6 +304,62 @@ export const WithGridSpan: Story = {),};+const longTokens: SearchableItem[] = [+ {id: 'short', label: 'Design'},+ {+ id: 'long',+ label:+ 'A long token label with spaces that is much wider than the 500px grid cell it sits in, so it has to truncate',+ },+];++const longTokenSource = {+ search: () => longTokens,+ bootstrap: () => longTokens,+};++export const GridSpanWithLongContent: Story = {+ name: 'GridSpan contains a long token (#7438)',+ render: () => (+ <div {...stylex.props(styles.container)}>+ <Text type="supporting" xstyle={styles.sectionLabel}>+ The dashed box is 500px wide. The long token truncates inside it.+ </Text>+ <div data-testid="host" {...stylex.props(styles.narrowHost)}>+ <Grid columns={{minWidth: 280, max: 2}} gap={4}>+ <GridSpan columns="full">+ <VStack>+ <Tokenizer+ label="Labels"+ width="100%"+ searchSource={longTokenSource}+ value={longTokens}+ onChange={() => {}}+ />+ </VStack>+ </GridSpan>+ </Grid>+ </div>+ </div>+ ),+ play: async ({canvasElement}) => {+ const host = canvasElement.querySelector('[data-testid="host"]');+ const span = host?.querySelector('.astryx-grid-span');+ const field = span?.firstElementChild;+ if (!host || !span || !field) {+ throw new Error('Expected the host, its GridSpan and the field stack');+ }+ // The span's single column must not grow past the host to fit a token.+ const hostRight = host.getBoundingClientRect().right;+ await expect(span.getBoundingClientRect().right).toBeLessThanOrEqual(+ hostRight + 0.5,+ );+ await expect(field.getBoundingClientRect().right).toBeLessThanOrEqual(+ hostRight + 0.5,+ );+ },+};+export const GridSpanWithRows: Story = {render: () => (<div {...stylex.props(styles.container)}>diff --git a/packages/core/src/Grid/GridSpan.tsx b/packages/core/src/Grid/GridSpan.tsxindex b487a56547..0fa1a4cf81 100644--- a/packages/core/src/Grid/GridSpan.tsx+++ b/packages/core/src/Grid/GridSpan.tsx@@ -47,6 +47,9 @@ const baseStyles = stylex.create({minWidth: 0, // Prevent overflow in grid// Make span fill grid cell and stretch childrendisplay: 'grid',+ // The implicit `auto` column would grow to a child's min-content width;+ // a zero minimum keeps it inside the span.+ gridTemplateColumns: 'minmax(0, 1fr)',height: '100%',},});