Skip to content

Commit

Permalink
Add underscore as an alt text antipattern (wagtail#12119)
Browse files Browse the repository at this point in the history
  • Loading branch information
albinazs authored Jul 16, 2024
1 parent 7074675 commit 62674d3
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion client/src/includes/a11y-result.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ describe('addCustomChecks', () => {

// Options for checkImageAltText function
const options = {
pattern: '\\.(avif|gif|jpg|jpeg|png|svg|webp)$',
pattern: '\\.(avif|gif|jpg|jpeg|png|svg|webp)$|_',
};

describe.each`
text | result
${'Good alt text with words like GIFted and motif'} | ${true}
${'Bad alt text.png'} | ${false}
${'Bad_alt_text'} | ${false}
${''} | ${true}
`('checkImageAltText', ({ text, result }) => {
const resultText = result ? 'should not be flagged' : 'should be flagged';
Expand Down
2 changes: 1 addition & 1 deletion client/src/includes/a11y-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const getAxeConfiguration = (

/**
* Custom rule for checking image alt text. This rule checks if the alt text for images
* contains poor quality text like file extensions.
* contains poor quality text like file extensions or undescores.
* The rule will be added via the Axe.configure() API.
* https://github.com/dequelabs/axe-core/blob/master/doc/API.md#api-name-axeconfigure
*/
Expand Down
2 changes: 1 addition & 1 deletion docs/advanced_topics/accessibility_considerations.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ By default, the checker includes the following rules to find common accessibilit
- `input-button-name`: `<input>` button elements must always have a text label.
- `link-name`: `<a>` link elements must always have a text label.
- `p-as-heading`: This rule checks for paragraphs that are styled as headings. Paragraphs should not be styled as headings, as they don’t help users who rely on headings to navigate content.
- `alt-text-quality`: A custom rule ensures that image alt texts don't contain anti-patterns like file extensions.
- `alt-text-quality`: A custom rule ensures that image alt texts don't contain anti-patterns like file extensions and underscores.

To customize how the checker is run (such as what rules to test), you can define a custom subclass of {class}`~wagtail.admin.userbar.AccessibilityItem` and override the attributes to your liking. Then, swap the instance of the default `AccessibilityItem` with an instance of your custom class via the [`construct_wagtail_userbar`](construct_wagtail_userbar) hook.

Expand Down
2 changes: 1 addition & 1 deletion docs/releases/6.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ depth: 1

### Alt text accessibility check

The [built-in accessibility checker](authoring_accessible_content) now enforces a new `alt-text-quality` rule, which tests alt text for the presence of known bad patterns such as file extensions. This rule is enabled by default, but can be disabled if necessary.
The [built-in accessibility checker](authoring_accessible_content) now enforces a new `alt-text-quality` rule, which tests alt text for the presence of known bad patterns such as file extensions and underscores. This rule is enabled by default, but can be disabled if necessary.

This feature was implemented by Albina Starykova, with support from the Wagtail accessibility team.

Expand Down
4 changes: 2 additions & 2 deletions wagtail/admin/tests/test_userbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ class CustomRulesAndChecksAccessibilityItem(AccessibilityItem):
axe_custom_checks = [
{
"id": "check-image-alt-text",
"options": {"pattern": "\\.[a-z]{1,4}$"},
"options": {"pattern": "\\.[a-z]{1,4}$|_"},
},
]

Expand Down Expand Up @@ -402,7 +402,7 @@ def get_axe_custom_checks(self, request):
"checks": [
{
"id": "check-image-alt-text",
"options": {"pattern": "\\.[a-z]{1,4}$"},
"options": {"pattern": "\\.[a-z]{1,4}$|_"},
},
{
"id": "check-link-text",
Expand Down
2 changes: 1 addition & 1 deletion wagtail/admin/userbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AccessibilityItem(BaseItem):
axe_custom_checks = [
{
"id": "check-image-alt-text",
"options": {"pattern": "\\.(avif|gif|jpg|jpeg|png|svg|webp)$"},
"options": {"pattern": "\\.(avif|gif|jpg|jpeg|png|svg|webp)$|_"},
},
]

Expand Down

0 comments on commit 62674d3

Please sign in to comment.