Skip to content

Commit 1ec57fc

Browse files
Remove autoscroll on product carousel
This removes a function which causes focus events to scroll the carousel to show card clicked (#15286)
1 parent 2340aa4 commit 1ec57fc

File tree

2 files changed

+0
-57
lines changed

2 files changed

+0
-57
lines changed

dotcom-rendering/src/components/ProductCarouselCard.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export const ProductCarouselCard = ({
109109
product.displayType !== 'ProductCardOnly' && (
110110
<Link
111111
href={`#${headingId}`}
112-
onFocus={(event) => event.stopPropagation()}
113112
cssOverrides={readMoreCta}
114113
data-component="at-a-glance-carousel-card-read-more"
115114
data-link-name="product read more link"

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -202,61 +202,6 @@ export const ScrollableProduct = ({ products, format }: Props) => {
202202
};
203203
};
204204

205-
/**
206-
* --- COPIED FROM ScrollableCarousel ---
207-
* Scrolls the carousel to a certain position when a card gains focus.
208-
*
209-
* If a card gains focus (e.g. by tabbing through the elements of the page) then the browser
210-
* will scroll the container to the focused card if it is NOT visible. If it is partially visible,
211-
* such as in the case with our carousel, then the browser will not bring the card in to view.
212-
* (Tested with Chrome and Firefox).
213-
*/
214-
const scrollToCardOnFocus = () => {
215-
const carouselElement = carouselRef.current;
216-
if (!carouselElement) return;
217-
218-
/**
219-
* We know the carousel has focus,
220-
*/
221-
let focusedCarouselPosition = null;
222-
for (const [index, element] of Array.from(
223-
carouselElement.childNodes,
224-
).entries()) {
225-
if (element.contains(document.activeElement)) {
226-
focusedCarouselPosition = index + 1;
227-
}
228-
}
229-
230-
/**
231-
* If none of the cards in the carousel have focus, we don't change the carousel scroll position.
232-
*/
233-
if (focusedCarouselPosition === null) return;
234-
235-
const cardWidth = carouselElement.querySelector('li')?.offsetWidth ?? 0;
236-
237-
/**
238-
* We use rounding as the users left scroll position is not always equal to the card width, but it is
239-
* very close. If the user is mid-scroll when starting focus on a carousel item (unlikely!) then the
240-
* scroll position is whichever is closest. We don't need to be exact as the number of carousel slides is small.
241-
*/
242-
const scrollPosition = Math.round(
243-
(carouselElement.scrollLeft + cardWidth) / cardWidth,
244-
);
245-
246-
/**
247-
* If the focused card is next to the card in the left-most position, then it
248-
* is not completely off-screen. It is either partially visible or entirely
249-
* visible (when the number of visible carousel slides is greater than 1).
250-
*
251-
* Bring this adjacent card into the left-most position.
252-
*/
253-
if (focusedCarouselPosition === scrollPosition + 1) {
254-
scrollTo('right');
255-
} else if (focusedCarouselPosition === scrollPosition - 1) {
256-
scrollTo('left');
257-
}
258-
};
259-
260205
/**
261206
* Update the count of the first card / how far scrolled the carousel is
262207
*
@@ -347,7 +292,6 @@ export const ScrollableProduct = ({ products, format }: Props) => {
347292
ref={carouselRef}
348293
css={carouselStyles}
349294
data-heatphan-type="carousel"
350-
onFocus={scrollToCardOnFocus}
351295
>
352296
{products.map(
353297
(product: ProductBlockElement, index: number) => (

0 commit comments

Comments
 (0)