@@ -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