Skip to content

Commit 8064164

Browse files
committed
Allow link clicks on carousels
1 parent 3da1e6c commit 8064164

File tree

4 files changed

+71
-48
lines changed

4 files changed

+71
-48
lines changed

dotcom-rendering/src/components/Card/Card.tsx

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -923,25 +923,21 @@ export const Card = ({
923923
isSmallCard={isSmallCard}
924924
>
925925
{media.type === 'slideshow' && (
926-
<div
927-
css={css`
928-
position: relative;
929-
z-index: ${getZIndex('card-nested-link')};
930-
`}
926+
<Island
927+
priority="feature"
928+
defer={{ until: 'visible' }}
931929
>
932-
<Island
933-
priority="feature"
934-
defer={{ until: 'visible' }}
935-
>
936-
<SlideshowCarousel
937-
images={media.slideshowImages}
938-
imageSize={mediaSize}
939-
hasNavigationBackgroundColour={
940-
!!hasSublinks
941-
}
942-
/>
943-
</Island>
944-
</div>
930+
<SlideshowCarousel
931+
images={media.slideshowImages}
932+
imageSize={mediaSize}
933+
hasNavigationBackgroundColour={
934+
!!hasSublinks
935+
}
936+
linkTo={linkTo}
937+
linkAriaLabel={headlineText}
938+
dataLinkName={resolvedDataLinkName}
939+
/>
940+
</Island>
945941
)}
946942
{media.type === 'avatar' && (
947943
<AvatarContainer

dotcom-rendering/src/components/Card/components/CardWrapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const hoverStyles = css`
5959
:has(
6060
ul.sublinks:hover,
6161
.video-container.loop:hover,
62-
.slideshow-carousel:hover,
62+
.slideshow-carousel-footer:hover,
6363
.branding-logo:hover
6464
) {
6565
.card-headline .show-underline {

dotcom-rendering/src/components/SlideshowCarousel.importable.tsx

Lines changed: 53 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
SvgChevronRightSingle,
1414
} from '@guardian/source/react-components';
1515
import { useEffect, useRef, useState } from 'react';
16+
import { getZIndex } from '../lib/getZIndex';
1617
import { takeFirst } from '../lib/tuple';
1718
import { palette } from '../palette';
1819
import type { DCRSlideshowImage } from '../types/front';
@@ -55,6 +56,11 @@ const carouselItemStyles = css`
5556
scroll-snap-align: start;
5657
`;
5758

59+
const carouselLinkStyles = css`
60+
position: relative;
61+
z-index: ${getZIndex('card-nested-link')};
62+
`;
63+
5864
const captionStyles = css`
5965
position: absolute;
6066
bottom: 0;
@@ -74,6 +80,8 @@ const navigationStyles = (hasBackgroundColour: boolean) => css`
7480
display: flex;
7581
align-items: center;
7682
padding-top: ${space[2]}px;
83+
position: relative;
84+
z-index: ${getZIndex('card-nested-link')};
7785
7886
${until.tablet} {
7987
background-color: ${hasBackgroundColour
@@ -108,12 +116,18 @@ type Props = {
108116
images: readonly DCRSlideshowImage[];
109117
imageSize: MediaSizeType;
110118
hasNavigationBackgroundColour: boolean;
119+
linkTo: string;
120+
linkAriaLabel: string;
121+
dataLinkName?: string;
111122
};
112123

113124
export const SlideshowCarousel = ({
114125
images,
115126
imageSize,
116127
hasNavigationBackgroundColour,
128+
linkTo,
129+
linkAriaLabel,
130+
dataLinkName,
117131
}: Props) => {
118132
const carouselRef = useRef<HTMLUListElement | null>(null);
119133
const [previousButtonEnabled, setPreviousButtonEnabled] = useState(false);
@@ -192,37 +206,47 @@ export const SlideshowCarousel = ({
192206
const slideshowImageCount = slideshowImages.length;
193207

194208
return (
195-
<div className="slideshow-carousel">
196-
<ul
197-
ref={carouselRef}
198-
css={carouselStyles}
199-
data-heatphan-type="carousel"
209+
<>
210+
<a
211+
href={linkTo}
212+
css={carouselLinkStyles}
213+
aria-label={linkAriaLabel}
214+
data-link-name={dataLinkName}
200215
>
201-
{slideshowImages.map((image, index) => {
202-
const loading = index > 0 ? 'lazy' : 'eager';
203-
return (
204-
<li css={carouselItemStyles} key={image.imageSrc}>
205-
<figure>
206-
<CardPicture
207-
mainImage={image.imageSrc}
208-
imageSize={imageSize}
209-
aspectRatio="5:4"
210-
alt={image.imageCaption}
211-
loading={loading}
212-
/>
213-
{!!image.imageCaption && (
214-
<figcaption css={captionStyles}>
215-
{image.imageCaption}
216-
</figcaption>
217-
)}
218-
</figure>
219-
</li>
220-
);
221-
})}
222-
</ul>
216+
<ul
217+
ref={carouselRef}
218+
css={carouselStyles}
219+
data-heatphan-type="carousel"
220+
>
221+
{slideshowImages.map((image, index) => {
222+
const loading = index > 0 ? 'lazy' : 'eager';
223+
return (
224+
<li css={carouselItemStyles} key={image.imageSrc}>
225+
<figure>
226+
<CardPicture
227+
mainImage={image.imageSrc}
228+
imageSize={imageSize}
229+
aspectRatio="5:4"
230+
alt={image.imageCaption}
231+
loading={loading}
232+
/>
233+
{!!image.imageCaption && (
234+
<figcaption css={captionStyles}>
235+
{image.imageCaption}
236+
</figcaption>
237+
)}
238+
</figure>
239+
</li>
240+
);
241+
})}
242+
</ul>
243+
</a>
223244

224245
{slideshowImageCount > 1 && (
225-
<div css={navigationStyles(hasNavigationBackgroundColour)}>
246+
<div
247+
className="slideshow-carousel-footer"
248+
css={navigationStyles(hasNavigationBackgroundColour)}
249+
>
226250
<div css={scrollingDotStyles}>
227251
<SlideshowCarouselScrollingDots
228252
total={slideshowImageCount}
@@ -266,6 +290,6 @@ export const SlideshowCarousel = ({
266290
</div>
267291
</div>
268292
)}
269-
</div>
293+
</>
270294
);
271295
};

dotcom-rendering/src/components/SlideshowCarousel.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ const meta = {
9191
images,
9292
imageSize: 'medium',
9393
hasNavigationBackgroundColour: false,
94+
linkTo: 'https://www.theguardian.com',
95+
linkAriaLabel: 'news | group-3 | card-@1 | media-slideshow',
96+
dataLinkName: 'slideshow-carousel',
9497
},
9598
render: (args) => (
9699
<Wrapper>

0 commit comments

Comments
 (0)