WordPress.org

Make WordPress Core

Changeset 46090


Ignore:
Timestamp:
09/11/2019 01:50:23 AM (10 days ago)
Author:
SergeyBiryukov
Message:

Accessibility: Comments: In comment_form(), remove aria-describedby attribute from the email field if there's no associated description in the comment_notes_before argument.

The attribute is meant to communicate to user agents and assistive technologies that the element has a description. If the referenced description is missing, it will be flagged as failure by any automated accessibility checker tool and, most importantly, is potentially confusing for assistive technologies users.

Props afercia, joedolson, dinhtungdu, donmhico, SergeyBiryukov.
Fixes #47975.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r46088 r46090  
    24292429    $args = array_merge( $defaults, $args );
    24302430
     2431    // Remove aria-describedby from the email field if there's no associated description.
     2432    if ( false === strpos( $args['comment_notes_before'], 'id="email-notes"' ) ) {
     2433        $args['fields']['email'] = str_replace(
     2434            ' aria-describedby="email-notes"',
     2435            '',
     2436            $args['fields']['email']
     2437        );
     2438    }
     2439
    24312440    /**
    24322441     * Fires before the comment form.
     
    25102519            endif;
    25112520
    2512             // Prepare an array of all fields, including the textarea
     2521            // Prepare an array of all fields, including the textarea.
    25132522            $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];
    25142523
  • trunk/tests/phpunit/tests/comment/commentForm.php

    r43531 r46090  
    1414            'label_submit' => 'foo-label',
    1515        );
     16
    1617        $form = get_echo( 'comment_form', array( $args, $p ) );
    1718
     
    3132            'submit_button' => '<input name="custom-%1$s" type="submit" id="custom-%2$s" class="custom-%3$s" value="custom-%4$s" />',
    3233        );
     34
    3335        $form = get_echo( 'comment_form', array( $args, $p ) );
    3436
     
    4749            'submit_field' => '<p class="my-custom-submit-field">%1$s %2$s</p>',
    4850        );
     51
    4952        $form = get_echo( 'comment_form', array( $args, $p ) );
    5053
     
    9598            ),
    9699        );
     100
    97101        $form = get_echo( 'comment_form', array( $args, $p ) );
    98102
     
    101105        $this->assertRegExp( '|<p class="comment\-form\-cookies\-consent">.*?</p>|', $form );
    102106    }
     107
     108    /**
     109     * @ticket 47975
     110     */
     111    public function test_aria_describedby_email_notes_should_not_be_added_if_no_email_notes() {
     112        $p = self::factory()->post->create();
     113
     114        $form_with_aria = get_echo( 'comment_form', array( array(), $p ) );
     115
     116        $this->assertContains( 'aria-describedby="email-notes"', $form_with_aria );
     117
     118        $args = array(
     119            'comment_notes_before' => '',
     120        );
     121
     122        $form_without_aria = get_echo( 'comment_form', array( $args, $p ) );
     123
     124        $this->assertNotContains( 'aria-describedby="email-notes"', $form_without_aria );
     125    }
    103126}
Note: See TracChangeset for help on using the changeset viewer.