File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -32,7 +32,11 @@ const Carousel = props => {
32
32
33
33
const useLink = item . href && true ;
34
34
const additionalProps = useLink
35
- ? { href : item . href , external_link : item . external_link }
35
+ ? {
36
+ href : item . href ,
37
+ external_link : item . external_link ,
38
+ target : item . target || '_self'
39
+ }
36
40
: { } ;
37
41
38
42
return (
@@ -167,6 +171,10 @@ Carousel.propTypes = {
167
171
* with the external_link argument.
168
172
*/
169
173
href : PropTypes . string ,
174
+ /**
175
+ * Optional target attribute for the link. Only applies if `href` is set, default `_self`.
176
+ */
177
+ target : PropTypes . string ,
170
178
/**
171
179
* If true, the browser will treat this as an external link,
172
180
* forcing a page refresh at the new location. If false,
Original file line number Diff line number Diff line change @@ -77,4 +77,45 @@ describe('Carousel', () => {
77
77
expect ( carouselItem ) . toHaveAttribute ( 'href' , '/test' ) ;
78
78
expect ( carouselItem . tagName . toLowerCase ( ) ) . toEqual ( 'a' ) ;
79
79
} ) ;
80
+
81
+ test ( 'carousel item external target' , ( ) => {
82
+ const linkedSlides = [
83
+ {
84
+ key : '0' ,
85
+ src : '' ,
86
+ alt : 'z' ,
87
+ href : 'http://www.example.com' ,
88
+ target : '_blank'
89
+ } ,
90
+ {
91
+ key : '1' ,
92
+ src : '' ,
93
+ alt : 'z' ,
94
+ href : '/test' ,
95
+ target : '_self' ,
96
+ external_link : true
97
+ } ,
98
+ {
99
+ key : '2' ,
100
+ src : '' ,
101
+ alt : 'z' ,
102
+ href : 'http://www.example.com'
103
+ } ,
104
+ ...slides
105
+ ] ;
106
+
107
+ const carousel = render ( < Carousel items = { linkedSlides } /> ) ;
108
+ const carouselItems = carousel . container . querySelectorAll ( '.carousel-item' ) ;
109
+ const blankTargetItem = carouselItems [ 0 ] ;
110
+ expect ( blankTargetItem ) . toHaveAttribute ( 'target' , '_blank' ) ;
111
+ expect ( blankTargetItem . tagName . toLowerCase ( ) ) . toEqual ( 'a' ) ;
112
+
113
+ const selfTargetItem = carouselItems [ 1 ] ;
114
+ expect ( selfTargetItem ) . toHaveAttribute ( 'target' , '_self' ) ;
115
+ expect ( selfTargetItem . tagName . toLowerCase ( ) ) . toEqual ( 'a' ) ;
116
+
117
+ const defaultTargetItem = carouselItems [ 2 ] ;
118
+ expect ( defaultTargetItem ) . toHaveAttribute ( 'target' , '_self' ) ;
119
+ expect ( defaultTargetItem . tagName . toLowerCase ( ) ) . toEqual ( 'a' ) ;
120
+ } ) ;
80
121
} ) ;
You can’t perform that action at this time.
0 commit comments