Skip to content

Commit

Permalink
test(tag): add aria-label test
Browse files Browse the repository at this point in the history
  • Loading branch information
dakahn committed Dec 11, 2019
1 parent 1c7d3b0 commit 846bd21
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 4 additions & 5 deletions packages/react/src/components/Tag/Tag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,16 @@ describe('Tag', () => {
describe('with a screenreader', () => {
afterEach(cleanup);

it('should have an aria-label', () => {
const { container } = render(
<Tag data-id="aliens">This is not a tag</Tag>
);
it('filtered variant should have appropriate aria-label', () => {
const { container } = render(<Tag filter>This is not a tag</Tag>);

const button = container.querySelector('[aria-label]');
expect(button).toBeInstanceOf(HTMLElement);

const ariaLabel = button.getAttribute('aria-label');
expect(ariaLabel).toBeDefined();

expect(ariaLabel).toEqual('Clear Filter This is not a tag');
expect(ariaLabel).toEqual('Clear filter This is not a tag');
});
});

Expand Down
6 changes: 5 additions & 1 deletion packages/react/src/components/Tag/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ const Tag = ({
return filter ? (
<button
className={tagClasses}
aria-label={`${title} ${children}` || `Clear filter ${children}`}
aria-label={
title !== undefined
? `${title} ${children}`
: `Clear filter ${children}`
}
{...other}>
{children !== null && children !== undefined ? children : TYPES[type]}
<Close16 />
Expand Down

0 comments on commit 846bd21

Please sign in to comment.