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

WIP: fix(eslint-plugin-lit-a11y): fix required aria-controls #1944

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,12 +54,18 @@ const RoleHasRequiredAriaAttrsRule = {
// if element has a role attr
if (Object.keys(element.attribs).includes('role')) {
const { role } = element.attribs;
const isNotAriaControls = attr => attr !== 'aria-controls';

// if the role is a valid/existing role
if (isAriaRole(role)) {
const requiredAriaAttributes = Object.keys(roles.get(role).requiredProps).sort();
const requiredAriaAttributes = Object.keys(roles.get(role).requiredProps)
.filter(isNotAriaControls)
.sort();
const presentAriaAttributes = Object.keys(element.attribs)
.filter(isNotAriaControls)
.filter(attr => attr.startsWith('aria-'))
.sort();

const hasRequiredAriaAttributes = requiredAriaAttributes.every(
(attr, i) => attr === presentAriaAttributes[i],
);
Expand Down
Expand Up @@ -30,8 +30,9 @@ ruleTester.run('role-has-required-aria-attrs', rule, {
'html`<span role="checkbox" aria-checked="false" aria-labelledby="foo" tabindex="0"></span>`',
},
{ code: 'html`<span role="row"></span>`' },
{ code: 'html`<span role="${foo}"></span>`' },
{ code: 'html`<span role="checkbox" aria-checked=${true}></span>`' },
{ code: 'html`<input type="checkbox" role="switch" aria-checked="true" />`' },
{ code: 'html`<div role="combobox" aria-controls="foo" aria-expanded="foo"></div>`' },
Copy link
Contributor

Choose a reason for hiding this comment

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

Why remove what looks like a valid combo box usage? Seems like we’d want to test this...

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add this as <div role="combobox" aria-expanded="foo"></div> instead of removing?

],

invalid: [
Expand All @@ -43,8 +44,7 @@ ruleTester.run('role-has-required-aria-attrs', rule, {
code: "html`<div role='combobox'></div>`",
errors: [
{
message:
'The "combobox" role requires the attributes "aria-controls" and "aria-expanded".',
message: 'The "combobox" role requires the attribute "aria-expanded".',
},
],
},
Expand Down