Skip to content

Commit

Permalink
fix: improving accessibility on buttons without text
Browse files Browse the repository at this point in the history
  • Loading branch information
Aegean09 committed Apr 30, 2024
1 parent bef4a18 commit 5836ecb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
10 changes: 10 additions & 0 deletions __tests__/arrow.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,14 @@ describe('<Arrow />', () => {
fireEvent.click(getByRole('button'));
expect(onClick).toHaveBeenCalled();
});

it('should have the correct aria-label when direction is right', () => {
const { getByRole } = render(<Arrow direction="right" />);
expect(getByRole('button')).toHaveAttribute('aria-label', 'Sağa kaydır');
});

it('should have the correct aria-label when direction is left', () => {
const { getByRole } = render(<Arrow direction="left" />);
expect(getByRole('button')).toHaveAttribute('aria-label', 'Sola kaydır');
});
});
21 changes: 20 additions & 1 deletion __tests__/scrollingCarousel.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { MouseEvent } from 'react';
import { render, cleanup, fireEvent, wait } from '@testing-library/react';
import { render, cleanup, fireEvent, wait, waitFor } from '@testing-library/react';
import { ScrollingCarousel } from '../src';
import { carouselItemNodes } from './__fixtures__/nodes';
import * as helpers from '../src/helpers';
Expand Down Expand Up @@ -102,4 +102,23 @@ describe('<ScrollingCarousel />', () => {
expect(container.querySelector('.sliding')).toBeInTheDocument();
});
});

it('should remove sliding class when isDown is false', async () => {
const { getByTestId } = render(
<ScrollingCarousel
triggerClickOn={3}
leftIcon={<i />}
children={carouselItemNodes(6)}
/>,
);

const sliderList = getByTestId('sliderList');
fireEvent.mouseDown(sliderList, { pageX: 600 });
fireEvent.mouseMove(sliderList, { pageX: 605 }); // Ensure some movement occurs
fireEvent.mouseUp(sliderList);

await waitFor(() => {
expect(sliderList).not.toHaveClass('sliding');
});
});
});
1 change: 1 addition & 0 deletions src/components/arrow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styles from '../../styles/styles.module.css';

export const Arrow: FunctionComponent<ArrowProps> = (props: ArrowProps) => (
<button
aria-label={`${props.direction === 'right' ? 'Sağa' : 'Sola'} kaydır`}
className={styles.carouselArrow}
onClick={props.onClick}
data-direction={props.direction}
Expand Down
2 changes: 1 addition & 1 deletion src/components/scrolling-carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const ScrollingCarousel: FunctionComponent<SliderProps> = (
) => {
return (
<div data-arrow={data} onClick={() => slide(direction)}>
{element ?? <button />}
{element ?? <button aria-label={`${data === 'right' ? 'Sağa' : 'Sola'} kaydır`} />}
</div>
);
};
Expand Down

0 comments on commit 5836ecb

Please sign in to comment.