Skip to content

Commit 648f28e

Browse files
author
Kubit
committed
Include aria-label prop to Carousel
1 parent 3f0b125 commit 648f28e

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/components/carousel/__tests__/carousel.test.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,4 +479,22 @@ describe('Carousel component', () => {
479479

480480
expect(indicator1).toBeInTheDocument();
481481
});
482+
483+
it('Should have aria-label in the document when prop is set', async () => {
484+
const { getByLabelText } = renderProvider(
485+
<CarouselUnControlled {...mockProps} aria-label='Mock aria-label'/>
486+
);
487+
488+
const label = getByLabelText('Mock aria-label');
489+
expect(label).toBeInTheDocument();
490+
});
491+
492+
it('Should not have aria-label in the document when prop is not set', async () => {
493+
const { queryByLabelText } = renderProvider(
494+
<CarouselUnControlled {...mockProps} />
495+
);
496+
497+
const label = queryByLabelText('');
498+
expect(label).not.toBeInTheDocument();
499+
});
482500
});

src/components/carousel/carouselStandAlone.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ const CarouselStandAloneComponent = (
8282
allowModifySliceWidth={allowModifySliceWidth}
8383
aria-labelledby={props['aria-labelledby']}
8484
aria-roledescription="carousel"
85+
aria-label={props['aria-label']}
8586
data-testid={`${dataTestId}Wrapper`}
8687
styles={styles}
8788
onKeyDown={onKeyDown}

src/components/carousel/stories/argtypes.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,17 @@ export const argtypes = (variants: IThemeObjectVariants, themeSelected: string):
244244
category: CATEGORY_CONTROL.ACCESIBILITY,
245245
},
246246
},
247+
['aria-label']: {
248+
description: 'Carousel aria label',
249+
control: { type: 'text' },
250+
type: { name: 'string' },
251+
table: {
252+
type: {
253+
summary: 'string',
254+
},
255+
category: CATEGORY_CONTROL.ACCESIBILITY,
256+
},
257+
},
247258
displayArrowsOnCarousel: {
248259
description: 'Show the arrows on the carousel or on the Page Control',
249260
type: { name: 'boolean' },

src/components/carousel/types/carousel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type PageControlAutomateConfigType = Omit<
2323
mediaProgressBar: CarouselMediaProgressBarType;
2424
};
2525

26-
type CarouselAriaAttributes = Pick<React.AriaAttributes, 'aria-labelledby' | 'aria-live'>;
26+
type CarouselAriaAttributes = Pick<React.AriaAttributes, 'aria-labelledby' | 'aria-live' | 'aria-label'>;
2727

2828
export interface ICarouselStandAlone extends CarouselAriaAttributes {
2929
styles: CarouselPropsStylesType;

0 commit comments

Comments
 (0)