Skip to content

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

TypeScript

fix(Button): reflect elevation as a theme target (nightly audit of core/Button) (#5552)

Cindy Zhang9345b268ba64
diff --git a/.changeset/button-elevation-theme-target.md b/.changeset/button-elevation-theme-target.md
new file mode 100644
index 0000000000..7c6750b46d
--- /dev/null
+++ b/.changeset/button-elevation-theme-target.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] `Button` now reflects `elevation` as a theme target. The prop selected between four StyleX style objects but was missing from the sibling `themeProps('button')` call, so `data-elevation` never reached the DOM and no theme could style the axis — the same defect fixed on `Card` in #5491, and one `ButtonGroup` already had right. A button inside a `ButtonGroup` reports `none`, because the group owns the surface's elevation and the member paints flat. Every wrapper that forwards `ButtonProps` through to `Button` — `IconButton` — picks the reflection up with it. (`ToggleButton` does not: its props extend `BaseProps`, not `ButtonProps`, so it has no `elevation` to forward and keeps reporting `none`.) Nothing about the rendered button changes: 60 of 64 captured frames are byte-identical, and the four that differ do so only inside the loading spinner's own box.
+
+@cixzhang
diff --git a/packages/core/src/Button/Button.doc.mjs b/packages/core/src/Button/Button.doc.mjs
index 26f76dc75a..856497fd0f 100644
--- a/packages/core/src/Button/Button.doc.mjs
+++ b/packages/core/src/Button/Button.doc.mjs
@@ -181,7 +181,7 @@ export const docs = {
},
theming: {
targets: [
- {className: 'astryx-button', visualProps: ['size', 'variant']},
+ {className: 'astryx-button', visualProps: ['size', 'variant', 'elevation']},
],
vars: [
{name: '--_button-radius', description: 'Border radius', default: 'var(--radius-element)', private: true},
@@ -262,6 +262,7 @@ export const docsZh = {
visualProps: [
'size',
'variant',
+ 'elevation',
],
},
],
diff --git a/packages/core/src/Button/Button.test.tsx b/packages/core/src/Button/Button.test.tsx
index 4ffac1fe3e..d8914f04d1 100644
--- a/packages/core/src/Button/Button.test.tsx
+++ b/packages/core/src/Button/Button.test.tsx
@@ -476,6 +476,21 @@ describe('Button', () => {
});
describe('elevation', () => {
+ it('reflects each elevation level as a theme attribute', () => {
+ const attrFor = (elevation: 'none' | 'low' | 'med' | 'high') => {
+ const {container} = render(
+ <Button label="Save" elevation={elevation} />,
+ );
+ return container
+ .querySelector('button')!
+ .getAttribute('data-elevation');
+ };
+ expect(attrFor('none')).toBe('none');
+ expect(attrFor('low')).toBe('low');
+ expect(attrFor('med')).toBe('med');
+ expect(attrFor('high')).toBe('high');
+ });
+
it('renders a distinct class for each elevation level', () => {
const classFor = (elevation: 'none' | 'low' | 'med' | 'high') => {
const {container} = render(
@@ -493,13 +508,13 @@ describe('Button', () => {
});
it('defaults to flat (elevation none)', () => {
- const {container: def} = render(<Button label="Save" />);
+ const {container} = render(<Button label="Save" />);
+ const button = container.querySelector('button')!;
+ expect(button).toHaveAttribute('data-elevation', 'none');
const {container: none} = render(
<Button label="Save" elevation="none" />,
);
- expect(def.querySelector('button')!.className).toBe(
- none.querySelector('button')!.className,
- );
+ expect(button.className).toBe(none.querySelector('button')!.className);
});
});
diff --git a/packages/core/src/Button/Button.tsx b/packages/core/src/Button/Button.tsx
index 8a70a00dcf..c261975aad 100644
--- a/packages/core/src/Button/Button.tsx
+++ b/packages/core/src/Button/Button.tsx
@@ -689,7 +689,13 @@ export function Button({
);
const sharedMergedProps = mergeProps(
- themeProps('button', {variant, size}),
+ // Inside a group the group owns the surface's elevation, so the button
+ // reflects the tier it actually paints rather than the prop it was handed.
+ themeProps('button', {
+ variant,
+ size,
+ elevation: buttonGroup ? 'none' : elevation,
+ }),
sharedStylexProps,
className,
style,
diff --git a/packages/core/src/ButtonGroup/ButtonGroup.test.tsx b/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
index db807d683a..87d8910e72 100644
--- a/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
+++ b/packages/core/src/ButtonGroup/ButtonGroup.test.tsx
@@ -626,6 +626,19 @@ describe('ButtonGroup', () => {
'high',
);
});
+
+ it('reports flat on a member, since the group owns the surface', () => {
+ render(
+ <ButtonGroup label="Actions" elevation="high">
+ <Button label="One" elevation="high" />
+ </ButtonGroup>,
+ );
+
+ expect(screen.getByRole('button', {name: 'One'})).toHaveAttribute(
+ 'data-elevation',
+ 'none',
+ );
+ });
});
// ===========================================================================