Skip to content

Ignore a11y href warnings if role="button" set #1763

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

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
36 changes: 23 additions & 13 deletions src/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,22 +365,32 @@ export default class Element extends Node {

// handle special cases
if (this.name === 'a') {
const attribute = attributeMap.get('href') || attributeMap.get('xlink:href');
const hrefAttribute = attributeMap.get('href') || attributeMap.get('xlink:href');

if (attribute) {
const value = attribute.getStaticValue();
const roleAttribute = attributeMap.get('role');
let hasButtonRole = false

if (value === '' || value === '#') {
component.warn(attribute, {
code: `a11y-invalid-attribute`,
message: `A11y: '${value}' is not a valid ${attribute.name} attribute`
if (roleAttribute) {
const roleValue = roleAttribute.getStaticValue();
hasButtonRole = (roleValue === 'button')
}

if (!hasButtonRole) {
if (hrefAttribute) {
const value = hrefAttribute.getStaticValue();

if (value === '' || value === '#') {
component.warn(hrefAttribute, {
code: `a11y-invalid-attribute`,
message: `A11y: '${value}' is not a valid ${hrefAttribute.name} attribute`
});
}
} else {
component.warn(this, {
code: `a11y-missing-attribute`,
message: `A11y: <a> element should have an href attribute`
});
}
} else {
component.warn(this, {
code: `a11y-missing-attribute`,
message: `A11y: <a> element should have an href attribute`
});
}
}

Expand Down Expand Up @@ -633,4 +643,4 @@ function shouldHaveAttribute(
code: `a11y-missing-attribute`,
message: `A11y: <${name}> element should have ${article} ${sequence} attribute`
});
}
}