Skip to content

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

TypeScript

fix(core): a caller's data-color no longer replaces Link's reflected data-color (#9157)

Parinitheca51a83cd40
diff --git a/.changeset/link-reflected-data-color.md b/.changeset/link-reflected-data-color.md
new file mode 100644
index 0000000000..08c509a881
--- /dev/null
+++ b/.changeset/link-reflected-data-color.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] A caller's `data-color` no longer replaces the one `Link` reflects for theme targeting (`architecture:public-component-api` INV5, `Link` FR11). Before, caller props were spread after the theme attributes, so passing `data-color` changed what theme rules saw on the root even though the real `color` prop was unchanged. This holds for the anchor, button and disabled forms. Other caller `data-*` attributes still reach the root.
+
+@parinith-web
diff --git a/packages/core/src/Link/Link.test.tsx b/packages/core/src/Link/Link.test.tsx
index ebd2bc7cc8..be905397a1 100644
--- a/packages/core/src/Link/Link.test.tsx
+++ b/packages/core/src/Link/Link.test.tsx
@@ -431,6 +431,35 @@ describe('Link', () => {
expect(link.className).toContain('astryx-link');
expect(link).toHaveAttribute('data-color', 'secondary');
});
+
+ it('keeps the reflected data-color when a caller passes its own', () => {
+ const callerProps = {'data-color': 'danger'};
+ render(
+ <>
+ <Link href="/test" color="secondary" {...callerProps}>
+ Anchor Link
+ </Link>
+ <Link color="secondary" onClick={() => {}} {...callerProps}>
+ Button Link
+ </Link>
+ <Link href="/test" color="secondary" isDisabled {...callerProps}>
+ Disabled Link
+ </Link>
+ </>,
+ );
+ expect(screen.getByRole('link', {name: 'Anchor Link'})).toHaveAttribute(
+ 'data-color',
+ 'secondary',
+ );
+ expect(screen.getByRole('button', {name: 'Button Link'})).toHaveAttribute(
+ 'data-color',
+ 'secondary',
+ );
+ expect(screen.getByRole('link', {name: 'Disabled Link'})).toHaveAttribute(
+ 'data-color',
+ 'secondary',
+ );
+ });
});
describe('pressed state', () => {
diff --git a/packages/core/src/Link/Link.tsx b/packages/core/src/Link/Link.tsx
index 3efed09e87..9877970365 100644
--- a/packages/core/src/Link/Link.tsx
+++ b/packages/core/src/Link/Link.tsx
@@ -43,7 +43,7 @@ import type {LinkComponentType} from './types';
import {mergeProps} from '../utils';
import {computeTargetAndRel} from './computeTargetAndRel';
import {useInteractiveRole} from '../hooks/useInteractiveRole';
-import {themeProps} from '../utils/themeProps';
+import {themeDataAttributes, themeProps} from '../utils/themeProps';
import {focusOutlineProps} from '../utils/focusOutline.stylex';
import {interactionOverlayStyles} from '../utils/interactionOverlay.stylex';
import {usePressFeedback} from '../hooks/usePressFeedback';
@@ -335,6 +335,10 @@ export function Link({
const renderAsButton =
role === 'button' || (role === 'inert' && href == null);
+ // The reflected theme attributes win over a caller's same-named `data-*`, so
+ // theme targeting always sees the real value (public-component-api INV5).
+ const reflectedAttributes = themeDataAttributes({color});
+
const sharedContent = (
<>
<Text
@@ -385,6 +389,7 @@ export function Link({
style,
)}
{...props}
+ {...reflectedAttributes}
// Focusable while disabled (spec:AST-085 FR1), but inert (FR2).
{...(isDisabled ? disabledInteractionProps(props.onKeyDown) : null)}>
{sharedContent}
@@ -419,6 +424,7 @@ export function Link({
style,
)}
{...props}
+ {...reflectedAttributes}
{...disabledInteractionProps(props.onKeyDown)}>
{sharedContent}
</a>
@@ -450,7 +456,8 @@ export function Link({
className,
style,
)}
- {...props}>
+ {...props}
+ {...reflectedAttributes}>
{sharedContent}
</LinkComponent>
);