-
Notifications
You must be signed in to change notification settings - Fork 305
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
Changes from 2 commits
d249a01
c30cdb1
3e1d876
a566495
5a4840a
f1a4459
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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; | ||
/** 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) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can we sort these? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} | ||
|
@@ -27,4 +34,5 @@ const CloseButton = ({ className, onClick }: CloseButtonProps) => { | |
); | ||
}; | ||
|
||
export default CloseButton; | ||
export { CloseButton as CloseButtonBase }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,12 @@ describe('components/close-button/CloseButton', () => { | |
expect(handleClick).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('accesability properties', () => { | ||
test('should have an accesiblity label', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we move this into the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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'); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorted.