File tree Expand file tree Collapse file tree 2 files changed +23
-6
lines changed
packages/react/src/components/Link Expand file tree Collapse file tree 2 files changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,27 @@ describe('Link', () => {
49
49
expect ( screen . getByRole ( 'link' ) ) . toHaveClass ( 'custom-class' ) ;
50
50
} ) ;
51
51
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
+
52
73
it ( 'should support being disabled' , ( ) => {
53
74
render (
54
75
< Link href = "https://carbondesignsystem.com" disabled >
Original file line number Diff line number Diff line change @@ -14,12 +14,8 @@ import React, {
14
14
ElementType ,
15
15
HTMLAttributeAnchorTarget ,
16
16
} from 'react' ;
17
+ import { PolymorphicComponentPropWithRef } from '../../internal/PolymorphicProps' ;
17
18
import { usePrefix } from '../../internal/usePrefix' ;
18
- import { PolymorphicProps } from '../../types/common' ;
19
- import {
20
- PolymorphicComponentPropWithRef ,
21
- PolymorphicRef ,
22
- } from '../../internal/PolymorphicProps' ;
23
19
24
20
export interface LinkBaseProps extends AnchorHTMLAttributes < HTMLAnchorElement > {
25
21
/**
@@ -110,7 +106,7 @@ const LinkBase = React.forwardRef<
110
106
} ) ;
111
107
const rel = target === '_blank' ? 'noopener' : undefined ;
112
108
const linkProps : AnchorHTMLAttributes < HTMLAnchorElement > = {
113
- className : BaseComponent ? undefined : className ,
109
+ className,
114
110
rel,
115
111
target,
116
112
} ;
You can’t perform that action at this time.
0 commit comments