Skip to content

Commit 3f2c47a

Browse files
pattonwebzclaude
andcommitted
Fix: narrow cover block selector exclusion to specific decorative classes
The broad [class*="wp-block-cover"] substring match excluded ANY element whose class contained that string — including the outer .wp-block-cover container and .wp-block-cover__inner-container, which hold real user content. If aria-hidden="true" were incorrectly placed on either, the checker would silently miss it. WordPress core only places aria-hidden="true" on two specific decorative child elements: .wp-block-cover__background (colour overlay) and .wp-block-cover__image-background (background image). Use those exact classes in the selector instead. Also adds a comment documenting each exclusion, and replaces the false- negative passing test for the outer container with a correct failing test. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent c442c9f commit 3f2c47a

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/pageScanner/rules/aria-hidden-validation.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
export default {
22
id: 'aria_hidden_validation',
3-
selector: '[aria-hidden="true"]:not([class*="wp-block-cover"]):not(.wp-block-spacer):not(.wp-block-separator)',
3+
// WordPress core block elements that legitimately use aria-hidden="true" on decorative content:
4+
// wp-block-cover__background — colour overlay span inside a cover block
5+
// wp-block-cover__image-background — background image inside a cover block
6+
// wp-block-spacer — intentionally empty spacing element
7+
// wp-block-separator — decorative HR element
8+
selector: '[aria-hidden="true"]:not(.wp-block-cover__background):not(.wp-block-cover__image-background):not(.wp-block-spacer):not(.wp-block-separator)',
49
excludeHidden: false,
510
tags: [
611
'wcag2a',

tests/jest/rules/ariaHiddenValid.test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ describe( 'Aria Hidden Validation', () => {
9898
html: '<img class="wp-block-cover__image-background wp-image-123" alt="" src="/photo.jpg" aria-hidden="true">',
9999
shouldPass: true,
100100
},
101-
{
102-
name: 'should pass for cover block container element with aria-hidden',
103-
html: '<div class="wp-block-cover" aria-hidden="true"><div class="wp-block-cover__inner-container"><p>Content</p></div></div>',
104-
shouldPass: true,
105-
},
106101
{
107102
name: 'should pass for element with role="presentation"',
108103
html: '<div role="presentation" aria-hidden="true">Content</div>',
@@ -205,6 +200,13 @@ describe( 'Aria Hidden Validation', () => {
205200
html: '<h2 aria-hidden="true">Important heading</h2>',
206201
shouldPass: false,
207202
},
203+
{
204+
// The outer .wp-block-cover container holds real content and is not
205+
// excluded by the selector — only the decorative child elements are.
206+
name: 'should fail for aria-hidden="true" on the outer cover block container (hides real content)',
207+
html: '<div class="wp-block-cover" aria-hidden="true"><div class="wp-block-cover__inner-container"><p>Visible content</p></div></div>',
208+
shouldPass: false,
209+
},
208210
{
209211
name: 'should fail for aria-hidden on form controls',
210212
html: '<input type="text" aria-hidden="true">',

0 commit comments

Comments
 (0)