Skip to content

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

TypeScript

fix(Grid): keep theme metadata authoritative (#7788)

Cindy Zhang72db6f9220cf
diff --git a/.changeset/grid-theme-metadata.md b/.changeset/grid-theme-metadata.md
new file mode 100644
index 0000000000..940d4e2f77
--- /dev/null
+++ b/.changeset/grid-theme-metadata.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Keep `Grid`'s theming metadata authoritative when callers pass conflicting data attributes.
+
+@cixzhang
diff --git a/packages/core/src/Grid/Grid.test.tsx b/packages/core/src/Grid/Grid.test.tsx
index 376e176436..72a8204e22 100644
--- a/packages/core/src/Grid/Grid.test.tsx
+++ b/packages/core/src/Grid/Grid.test.tsx
@@ -308,6 +308,28 @@ describe('Grid', () => {
expect(grid).toHaveAttribute('aria-label', 'Product grid');
});
+ it('keeps component-owned theme metadata over colliding pass-throughs', () => {
+ render(
+ <Grid
+ columns={3}
+ gap={4}
+ align="end"
+ justify="center"
+ data-columns="9"
+ data-gap="10"
+ data-align="start"
+ data-justify="stretch"
+ data-testid="grid">
+ <div>Item</div>
+ </Grid>,
+ );
+ const grid = screen.getByTestId('grid');
+ expect(grid).toHaveAttribute('data-columns', '3');
+ expect(grid).toHaveAttribute('data-gap', '4');
+ expect(grid).toHaveAttribute('data-align', 'end');
+ expect(grid).toHaveAttribute('data-justify', 'center');
+ });
+
it('renders children correctly', () => {
render(
<Grid columns={3} data-testid="grid">
diff --git a/packages/core/src/Grid/Grid.tsx b/packages/core/src/Grid/Grid.tsx
index be4597945c..7f77ed3493 100644
--- a/packages/core/src/Grid/Grid.tsx
+++ b/packages/core/src/Grid/Grid.tsx
@@ -455,6 +455,7 @@ export function Grid({
return (
<div
ref={ref}
+ {...props}
{...mergeProps(
themeProps('grid', {columns: columnsVariant, gap, align, justify}),
stylex.props(
@@ -470,8 +471,7 @@ export function Grid({
),
className,
{...style, ...inlineStyle},
- )}
- {...props}>
+ )}>
{children}
</div>
);