From 28cb3451313e59df832fbd10e177a35d728c192e Mon Sep 17 00:00:00 2001 From: Echo Date: Thu, 30 Oct 2025 14:08:24 +0100 Subject: [PATCH] Fix: Ensure carousel focuses on wrapper (#36649) --- .../mastodon/components/carousel/index.tsx | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/javascript/mastodon/components/carousel/index.tsx b/app/javascript/mastodon/components/carousel/index.tsx index f2b9e9823b2..f5d772fd38d 100644 --- a/app/javascript/mastodon/components/carousel/index.tsx +++ b/app/javascript/mastodon/components/carousel/index.tsx @@ -90,9 +90,8 @@ export const Carousel = < const slide = wrapperRef.current?.children[newIndex]; if (slide) { setCurrentSlideHeight(slide.scrollHeight); - onChangeSlide?.(newIndex, slide); if (slide instanceof HTMLElement) { - slide.focus({ preventScroll: true }); + onChangeSlide?.(newIndex, slide); } } @@ -134,9 +133,13 @@ export const Carousel = < ); const handlePrev = useCallback(() => { handleSlideChange(-1); + // We're focusing on the wrapper as the child slides can potentially be inert. + // Because of that, only the active slide can be focused anyway. + wrapperRef.current?.focus(); }, [handleSlideChange]); const handleNext = useCallback(() => { handleSlideChange(1); + wrapperRef.current?.focus(); }, [handleSlideChange]); const intl = useIntl(); @@ -172,6 +175,11 @@ export const Carousel = < className={`${classNamePrefix}__slides`} ref={wrapperRef} style={wrapperStyles} + aria-label={intl.formatMessage(messages.slide, { + current: slideIndex + 1, + max: items.length, + })} + tabIndex={-1} > {items.map((itemsProps, index) => ( @@ -184,10 +192,6 @@ export const Carousel = < active: index === slideIndex, })} active={index === slideIndex} - label={intl.formatMessage(messages.slide, { - current: index + 1, - max: items.length, - })} /> ))} @@ -201,7 +205,6 @@ type CarouselSlideWrapperProps = { active: boolean; item: SlideProps; index: number; - label: string; } & Pick, 'renderItem'>; const CarouselSlideWrapper = ({ @@ -211,7 +214,6 @@ const CarouselSlideWrapper = ({ renderItem, item, index, - label, }: CarouselSlideWrapperProps) => { const handleRef = useCallback( (instance: HTMLDivElement | null) => { @@ -233,9 +235,7 @@ const CarouselSlideWrapper = ({ className={className} role='group' aria-roledescription='slide' - aria-label={label} inert={active ? undefined : ''} - tabIndex={-1} data-index={index} > {children}