Skip to content

Commit 57147ac

Browse files
fix(Link): class name logic refactor (#19384)
* fix(Link): class name logic refactor * fix(Link): always keep Carbon class names --------- Co-authored-by: Taylor Jones <[email protected]>
1 parent b8c7071 commit 57147ac

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

packages/react/src/components/Link/Link-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ describe('Link', () => {
4949
expect(screen.getByRole('link')).toHaveClass('custom-class');
5050
});
5151

52+
it('should support a custom class on the element with the as property', () => {
53+
render(
54+
<Link
55+
href="https://carbondesignsystem.com"
56+
as="h1"
57+
className="custom-class">
58+
test
59+
</Link>
60+
);
61+
expect(screen.getByRole('heading')).toHaveClass('custom-class');
62+
});
63+
64+
it('should keep Carbon classes on the element with the as property', () => {
65+
render(
66+
<Link href="https://carbondesignsystem.com" as="h1">
67+
test
68+
</Link>
69+
);
70+
expect(screen.getByRole('heading').classList.length).toBeTruthy();
71+
});
72+
5273
it('should support being disabled', () => {
5374
render(
5475
<Link href="https://carbondesignsystem.com" disabled>

packages/react/src/components/Link/Link.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,8 @@ import React, {
1414
ElementType,
1515
HTMLAttributeAnchorTarget,
1616
} from 'react';
17+
import { PolymorphicComponentPropWithRef } from '../../internal/PolymorphicProps';
1718
import { usePrefix } from '../../internal/usePrefix';
18-
import { PolymorphicProps } from '../../types/common';
19-
import {
20-
PolymorphicComponentPropWithRef,
21-
PolymorphicRef,
22-
} from '../../internal/PolymorphicProps';
2319

2420
export interface LinkBaseProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
2521
/**
@@ -110,7 +106,7 @@ const LinkBase = React.forwardRef<
110106
});
111107
const rel = target === '_blank' ? 'noopener' : undefined;
112108
const linkProps: AnchorHTMLAttributes<HTMLAnchorElement> = {
113-
className: BaseComponent ? undefined : className,
109+
className,
114110
rel,
115111
target,
116112
};

0 commit comments

Comments
 (0)