From a01cd59101822533a5737f162084df694fa5c110 Mon Sep 17 00:00:00 2001 From: kkmch Date: Tue, 10 Oct 2023 12:30:05 +0200 Subject: [PATCH] fix: bar and inert prop setting --- src/blocks/Slider/Slider.tsx | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/blocks/Slider/Slider.tsx b/src/blocks/Slider/Slider.tsx index 12171add5..df97e5086 100644 --- a/src/blocks/Slider/Slider.tsx +++ b/src/blocks/Slider/Slider.tsx @@ -251,7 +251,7 @@ export const SliderBlock = (props: WithChildren) => { return ( // To have this key differ from keys used in renderDot function, added `-accessible-bar` part - {slidesCountByBreakpoint > 1 && ( + {slidesCountByBreakpoint > 0 && (
  • ) => { ); }; - const renderDot = (index: number) => { + const getCurrentSlideNumber = (index: number) => { const currentIndexDiff = index - currentIndex; + let currentSlideNumber; if (0 <= currentIndexDiff && currentIndexDiff < slidesToShowCount) { currentSlideNumber = currentIndex + 1; @@ -276,19 +277,26 @@ export const SliderBlock = (props: WithChildren) => { } else { currentSlideNumber = index + 1; } + return currentSlideNumber; + }; + const isVisibleSlide = (index: number) => { + const currentIndexDiff = index - currentIndex; + return ( + slidesCountByBreakpoint > 0 && + 0 <= currentIndexDiff && + currentIndexDiff < slidesToShowCount + ); + }; + + const renderDot = (index: number) => { return (
  • handleDotClick(index)} - aria-hidden={ - (slidesCountByBreakpoint > 1 && - 0 <= currentIndexDiff && - currentIndexDiff < slidesToShowCount) || - undefined - } - aria-label={`Slide ${currentSlideNumber} of ${barSlidesCount}`} + aria-hidden={isVisibleSlide(index) ? true : undefined} + aria-label={`Slide ${getCurrentSlideNumber(index)} of ${barSlidesCount}`} >
  • ); }; @@ -349,7 +357,7 @@ export const SliderBlock = (props: WithChildren) => { {React.Children.map(disclosedChildren, (child, i) => { //@ts-ignore to prevent focusable elements from other slides being focused - return
    {child}
    ; + return
    {child}
    ; })}