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(Tag): adds various fixes for screen reader accessibility; adds AAT #4863

Merged
merged 21 commits into from
Jan 6, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3bdb91a
fix(filter): add role button and update story for clarity
dakahn Dec 5, 2019
0304691
Merge branch '4427-filtertags' of github.com:dakahn/carbon into 4427-…
dakahn Dec 9, 2019
49a2e0d
fix(tag): change span to button, remove role and add button-reset helper
dakahn Dec 9, 2019
5ad6d50
fix(tag): add button-reset to tag styling
dakahn Dec 9, 2019
cd5e8a0
chore(tag): sync with upstream master
dakahn Dec 10, 2019
180be7f
test(tag): add Axe test
dakahn Dec 10, 2019
ba059f0
fix(tag): remove unused aria, title, tab-index; add DAP
dakahn Dec 10, 2019
1c7d3b0
test(tag): add busted unit tests for screenreader HALP
dakahn Dec 11, 2019
846bd21
test(tag): add aria-label test
dakahn Dec 11, 2019
aa9728f
Merge branch 'master' into 4427-filtertags
dakahn Dec 11, 2019
fc275f6
Update packages/react/src/components/Tag/Tag-test.js
dakahn Dec 12, 2019
6beb042
Update packages/react/src/components/Tag/Tag-test.js
dakahn Dec 12, 2019
3f41457
Update packages/react/src/components/Tag/Tag-test.js
dakahn Dec 12, 2019
eaebfd0
Update packages/react/src/components/Tag/Tag-test.js
dakahn Dec 17, 2019
cf69e2f
test(tags): add less specific check for children for aria-label
dakahn Dec 17, 2019
e965060
test(tag): resolve merge conflict
dakahn Dec 17, 2019
8a8dff1
Merge branch 'master' into 4427-filtertags
dakahn Dec 17, 2019
177b1c0
Merge branch 'master' into 4427-filtertags
dakahn Dec 18, 2019
582848e
test(tag): add <main> wrapper for DAP test element
dakahn Dec 18, 2019
5e25686
Merge branch 'master' into 4427-filtertags
joshblack Jan 6, 2020
4f8795a
Merge branch 'master' into 4427-filtertags
joshblack Jan 6, 2020
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
1 change: 1 addition & 0 deletions packages/components/src/components/tag/_tag.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@mixin tags {
.#{$prefix}--tag {
@include type-style('label-01');
@include button-reset($width: false);

display: inline-flex;
position: relative;
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/Tag/Tag-story.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const props = {
'red'
),
disabled: boolean('Disabled (disabled)', false),
title: 'Clear Selection',
title: 'Clear Filter',
}),
filter() {
return { ...this.regular(), onClick: action('onClick') };
Expand Down
30 changes: 30 additions & 0 deletions packages/react/src/components/Tag/Tag-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,40 @@ import Tag from '../Tag';
import TagSkeleton from '../Tag/Tag.Skeleton';
import { shallow } from 'enzyme';
import { settings } from 'carbon-components';
import { render, cleanup } from '@carbon/test-utils/react';

const { prefix } = settings;

describe('Tag', () => {
afterEach(cleanup);

describe('automated accessibility testing', () => {
it('should have no Axe violations', async () => {
const { container } = render(<Tag>This is not a tag</Tag>);
await expect(container).toHaveNoAxeViolations();
});

it('should have no DAP violations', async () => {
const { container } = render(<Tag>This is not a tag</Tag>);
await expect(container).toHaveNoDAPViolations('Tag');
});
});

describe('with a screenreader', () => {

dakahn marked this conversation as resolved.
Show resolved Hide resolved
it('filtered variant should have appropriate aria-label', () => {
dakahn marked this conversation as resolved.
Show resolved Hide resolved
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');
dakahn marked this conversation as resolved.
Show resolved Hide resolved
});
});

describe('Renders as expected', () => {
it('should render with the appropriate type', () => {
const tag = shallow(<Tag type="beta" />);
Expand Down
18 changes: 10 additions & 8 deletions packages/react/src/components/Tag/Tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ const Tag = ({
[`${prefix}--tag--filter`]: filter,
});
return filter ? (
<span
role="button"
<button
className={tagClasses}
title={title || 'Clear filter'}
tabIndex="0" // eslint-disable-line jsx-a11y/no-noninteractive-tabindex
aria-label={
title !== undefined
? `${title} ${children}`
: `Clear filter ${children}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this so that we don't have a mismatch with the visual and accessible labels? Would there a preferred way to separate these or is this the ideal? Would we ever want something like:

<span class="tag">
  <button>Clear</button>
  Text for tag
</span>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, since we don't technically have a visual label for the X icon remove button this was just so it spoke clearly (as defined in the issue) in VO etc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

title is -- not what we want here, but removing or not incorporating the prop is a breaking change.

}
{...other}>
{children !== null && children !== undefined ? children : TYPES[type]}
<Close16 aria-label={title || 'Clear filter'} />
</span>
<Close16 />
</button>
) : (
<span className={tagClasses} {...other}>
<button className={tagClasses} {...other}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Do the other tag types need to be a button?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nah, I don't think so. They're non-interactable generally.

{children !== null && children !== undefined ? children : TYPES[type]}
</span>
</button>
);
};

Expand Down