Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(button): add aria labels for accessibility #3377

Merged
merged 6 commits into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/components/close-button/CloseButton.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import * as React from 'react';
import classNames from 'classnames';

import { injectIntl, IntlShape } from 'react-intl';

import Button, { ButtonType } from '../button';
import IconClose from '../../icons/general/IconClose';
import { bdlGray65 } from '../../styles/variables';

// @ts-ignore flow import
import messages from '../../common/messages';

import './CloseButton.scss';

export interface CloseButtonProps {
intl: IntlShape;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this list is sorted alphabetically

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted.

/** Custom class for the close button */
className?: string;
/** onClick handler for the close button */
onClick?: Function;
}

const CloseButton = ({ className, onClick }: CloseButtonProps) => {
const CloseButton = ({ intl, className, onClick }: CloseButtonProps) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we sort these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorted.

return (
<Button
aria-label={intl.formatMessage(messages.close)}
className={classNames('bdl-CloseButton', className)}
data-testid="bdl-CloseButton"
onClick={onClick}
Expand All @@ -27,4 +34,5 @@ const CloseButton = ({ className, onClick }: CloseButtonProps) => {
);
};

export default CloseButton;
export { CloseButton as CloseButtonBase };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually we do this export so that we can test the component without the injectIntl HOC. do we need to update the import in the test?

Copy link
Contributor Author

@dsporysz-box dsporysz-box Aug 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed an unused export, leaving just the one with injectIntl.

export default injectIntl(CloseButton);
8 changes: 8 additions & 0 deletions src/components/close-button/__tests__/CloseButton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,12 @@ describe('components/close-button/CloseButton', () => {
expect(handleClick).toHaveBeenCalledTimes(1);
});
});

describe('accesability properties', () => {
test('should have an accesiblity label', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we move this into the render() describe above? this test probably doesn't need to be in its own describe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it.

dsporysz-box marked this conversation as resolved.
Show resolved Hide resolved
render(<CloseButton />);
const closeButton = screen.getByRole('button');
expect(closeButton).toHaveAttribute('aria-label');
});
});
});
Loading