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

new_audit: table-fake-caption, html-xml-lang-mismatch, input-button-name #15098

Merged
merged 20 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from 16 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
6 changes: 6 additions & 0 deletions cli/test/fixtures/a11y/a11y_tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ <h3>sub-sub-header</h3>
src="./bogus.jpg">
</img>
</section>
<p>input-button-name</p>
<section>
<form action="#">
<input type="button" id="input-button-name" />
</form>
</section>
<p>input-image-alt</p>
<section>
<input type="image" id="input-image-alt">
Expand Down
36 changes: 36 additions & 0 deletions cli/test/smokehouse/test-definitions/a11y.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,10 @@ const expectations = {
],
},
},
'html-xml-lang-mismatch': {
score: null,
scoreDisplayMode: 'notApplicable',
},
Copy link
Member

@adamraine adamraine May 24, 2023

Choose a reason for hiding this comment

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

In order to test this, we would need to add lang and xml:lang attributes to the <html> tag? And that would force the existing html-has-lang audit to pass?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep! I figured that this is still useful because I wasn't sure if html-xml-lang-mismatch also checked for the existence + validity of the lang attribute -- as in, whether this was html-has-lang + checking xml:lang, which the docs seemed to imply. But given that this is notApplicable, seems like that's not the case, and this solely focuses on xml:lang.

'image-alt': {
score: 0,
details: {
Expand All @@ -568,6 +572,22 @@ const expectations = {
],
},
},
'input-button-name': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > form > input#input-button-name',
'snippet': '<input type="button" id="input-button-name">',
'explanation': 'Fix any of the following:\n Element has a value attribute and the value attribute is empty\n Element has no value attribute\n aria-label attribute does not exist or is empty\n aria-labelledby attribute does not exist, references elements that do not exist or references elements that are empty\n Element has no title attribute\n Element\'s default semantics were not overridden with role="none" or role="presentation"',
'nodeLabel': 'body > section > form > input#input-button-name',
},
},
],
},
},
'input-image-alt': {
score: 0,
details: {
Expand Down Expand Up @@ -698,6 +718,22 @@ const expectations = {
],
},
},
'table-fake-caption': {
score: 0,
details: {
items: [
{
node: {
'type': 'node',
'selector': 'body > section > table#table-fake-caption',
'snippet': '<table id="table-fake-caption" role="grid">',
'explanation': 'Fix all of the following:\n The first child of the table should be a caption instead of a table cell',
'nodeLabel': 'FOO\nfoo\tfoo\n',
},
},
],
},
},
'td-has-header': {
score: 0,
details: {
Expand Down
47 changes: 47 additions & 0 deletions core/audits/accessibility/html-xml-lang-mismatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

/**
* @fileoverview Ensures that, if present, the `[xml:lang]` attribute value in an HTML document has
* the same value as the `[lang]` attribute.
* See base class in axe-audit.js for audit() implementation.
*/

import AxeAudit from './axe-audit.js';
import * as i18n from '../../lib/i18n/i18n.js';

const UIStrings = {
/** Title of an accesibility audit that evaluates if the xml:lang attribute, if present, has the same value as the `lang` attribute. This title is descriptive of the successful state and is shown to users when no user action is required. */
title: '`<html>` element has an `[xml:lang]` attribute with the same value as the `[lang]` ' +
'attribute.',
jazyan marked this conversation as resolved.
Show resolved Hide resolved
/** Title of an accesibility audit that evaluates if the xml:lang attribute, if present, has the same value as the `lang` attribute. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
failureTitle: '`<html>` element does not have an `[xml:lang]` attribute with the same value ' +
'as the `[lang]` attribute.',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
failureTitle: '`<html>` element does not have an `[xml:lang]` attribute with the same value ' +
'as the `[lang]` attribute.',
failureTitle: '`<html>` element does not have an `[xml:lang]` attribute with the same base language ' +
'as the `[lang]` attribute.',

/** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
description: 'If the webpage does not specify a consistent language, then the screen ' +
'reader might not announce the page\'s text correctly. ' +
'[Learn more about the `lang` attribute](https://dequeuniversity.com/rules/axe/4.7/html-xml-lang-mismatch).',
};

const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);

class HTMLXMLLangMismatch extends AxeAudit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'html-xml-lang-mismatch',
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
requiredArtifacts: ['Accessibility'],
};
}
}

export default HTMLXMLLangMismatch;
export {UIStrings};
44 changes: 44 additions & 0 deletions core/audits/accessibility/input-button-name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @license Copyright 2017 The Lighthouse Authors. All Rights Reserved.
jazyan marked this conversation as resolved.
Show resolved Hide resolved
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

/**
* @fileoverview Ensures input buttons have discernible text.
* See base class in axe-audit.js for audit() implementation.
*/

import AxeAudit from './axe-audit.js';
import * as i18n from '../../lib/i18n/i18n.js';

const UIStrings = {
/** Title of an accesibility audit that evaluates if all input buttons have discernible text. This title is descriptive of the successful state and is shown to users when no user action is required. */
title: 'Input buttons have discernible text.',
/** Title of an accesibility audit that evaluates if all input buttons have discernible text. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
failureTitle: 'Input buttons do not have discernible text.',
/** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
description: 'Adding discernable and accessible text to input buttons may help screen reader ' +
'users understand the purpose of the input button. ' +
'[Learn more about input buttons](https://dequeuniversity.com/rules/axe/4.7/input-button-name).',
};

const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);

class InputButtonName extends AxeAudit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'input-button-name',
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
requiredArtifacts: ['Accessibility'],
};
}
}

export default InputButtonName;
export {UIStrings};
47 changes: 47 additions & 0 deletions core/audits/accessibility/table-fake-caption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* @license Copyright 2023 The Lighthouse Authors. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

/**
* @fileoverview Ensure that tables use `<caption>` instead of colspan for a caption.
* See base class in axe-audit.js for audit() implementation.
*/

import AxeAudit from './axe-audit.js';
import * as i18n from '../../lib/i18n/i18n.js';

const UIStrings = {
/** Title of an accesibility audit that evaluates if all tables use caption instead of colspan to indicate a caption. This title is descriptive of the successful state and is shown to users when no user action is required. */
title: 'Tables use `<caption>` instead of cells with the `[colspan]` attribute to indicate a ' +
'caption.',
/** Title of an accesibility audit that evaluates if all tables use caption instead of colspan to indicate a caption. This title is descriptive of the failing state and is shown to users when there is a failure that needs to be addressed. */
failureTitle: 'Tables do not use `<caption>` instead of cells with the `[colspan]` attribute ' +
'to indicate a caption.',
/** Description of a Lighthouse audit that tells the user *why* they should try to pass. This is displayed after a user expands the section to see more. No character length limits. The last sentence starting with 'Learn' becomes link text to additional documentation. */
description: 'Screen readers have features to make navigating tables easier. Ensuring ' +
'that tables use the actual caption element instead of cells with the `[colspan]` ' +
'attribute may improve the experience for screen reader users. ' +
'[Learn more about captions](https://dequeuniversity.com/rules/axe/4.7/table-fake-caption).',
};

const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings);

class TableFakeCaption extends AxeAudit {
/**
* @return {LH.Audit.Meta}
*/
static get meta() {
return {
id: 'table-fake-caption',
title: str_(UIStrings.title),
failureTitle: str_(UIStrings.failureTitle),
description: str_(UIStrings.description),
requiredArtifacts: ['Accessibility'],
};
}
}

export default TableFakeCaption;
export {UIStrings};
6 changes: 6 additions & 0 deletions core/config/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ const defaultConfig = {
'accessibility/heading-order',
'accessibility/html-has-lang',
'accessibility/html-lang-valid',
'accessibility/html-xml-lang-mismatch',
'accessibility/image-alt',
'accessibility/input-button-name',
'accessibility/input-image-alt',
'accessibility/label',
'accessibility/link-name',
Expand All @@ -273,6 +275,7 @@ const defaultConfig = {
'accessibility/meta-viewport',
'accessibility/object-alt',
'accessibility/tabindex',
'accessibility/table-fake-caption',
'accessibility/td-has-header',
'accessibility/td-headers-attr',
'accessibility/th-has-data-cells',
Expand Down Expand Up @@ -528,7 +531,9 @@ const defaultConfig = {
{id: 'heading-order', weight: 2, group: 'a11y-navigation'},
{id: 'html-has-lang', weight: 3, group: 'a11y-language'},
{id: 'html-lang-valid', weight: 3, group: 'a11y-language'},
{id: 'html-xml-lang-mismatch', weight: 2, group: 'a11y-language'},
{id: 'image-alt', weight: 10, group: 'a11y-names-labels'},
{id: 'input-button-name', weight: 10, group: 'a11y-names-labels'},
{id: 'input-image-alt', weight: 10, group: 'a11y-names-labels'},
{id: 'label', weight: 10, group: 'a11y-names-labels'},
{id: 'link-name', weight: 3, group: 'a11y-names-labels'},
Expand All @@ -538,6 +543,7 @@ const defaultConfig = {
{id: 'meta-viewport', weight: 10, group: 'a11y-best-practices'},
{id: 'object-alt', weight: 3, group: 'a11y-names-labels'},
{id: 'tabindex', weight: 3, group: 'a11y-navigation'},
{id: 'table-fake-caption', weight: 3, group: 'a11y-tables-lists'},
{id: 'td-has-header', weight: 10, group: 'a11y-tables-lists'},
{id: 'td-headers-attr', weight: 3, group: 'a11y-tables-lists'},
{id: 'th-has-data-cells', weight: 3, group: 'a11y-tables-lists'},
Expand Down
39 changes: 19 additions & 20 deletions core/gather/gatherers/accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,33 @@ async function runA11yChecks() {
resultTypes: ['violations', 'inapplicable'],
rules: {
// Consider http://go/prcpg for expert review of the aXe rules.
'tabindex': {enabled: true},
'accesskeys': {enabled: true},
'heading-order': {enabled: true},
'meta-viewport': {enabled: true},
'duplicate-id': {enabled: false},
'table-fake-caption': {enabled: false},
'td-has-header': {enabled: true},
'marquee': {enabled: false},
'area-alt': {enabled: false},
'html-xml-lang-mismatch': {enabled: false},
'aria-roledescription': {enabled: false},
'aria-treeitem-name': {enabled: true},
'audio-caption': {enabled: false},
'blink': {enabled: false},
'server-side-image-map': {enabled: false},
'duplicate-id': {enabled: false},
'frame-focusable-content': {enabled: false},
'frame-title-unique': {enabled: false},
'heading-order': {enabled: true},
'html-xml-lang-mismatch': {enabled: true},
'identical-links-same-purpose': {enabled: false},
'no-autoplay-audio': {enabled: false},
'svg-img-alt': {enabled: false},
'audio-caption': {enabled: false},
'aria-treeitem-name': {enabled: true},
'input-button-name': {enabled: true},
'link-in-text-block': {enabled: false},
'marquee': {enabled: false},
'meta-viewport': {enabled: true},
// https://github.com/dequelabs/axe-core/issues/2958
'nested-interactive': {enabled: false},
'frame-focusable-content': {enabled: false},
'aria-roledescription': {enabled: false},
'scrollable-region-focusable': {enabled: false},
// TODO(paulirish): create audits and enable these 5.
'input-button-name': {enabled: false},
'no-autoplay-audio': {enabled: false},
'role-img-alt': {enabled: false},
'scrollable-region-focusable': {enabled: false},
'select-name': {enabled: false},
'link-in-text-block': {enabled: false},
'frame-title-unique': {enabled: false},
'server-side-image-map': {enabled: false},
'svg-img-alt': {enabled: false},
'tabindex': {enabled: true},
'table-fake-caption': {enabled: true},
'td-has-header': {enabled: true},
},
});

Expand Down
Loading