Make WordPress Core

Changeset 60715


Ignore:
Timestamp:
09/07/2025 02:45:32 AM (2 months ago)
Author:
joedolson
Message:

Customizer: Accessible errors when adding new pages.

When setting the home page settings or dynamically adding new pages in the menu manager, the error messages didn't meet accessibility standards.

Add a screen reader announcement, a visible notification, and standardize the error styles.

Props dilipbheda, dlh, celloexpressions, joedolson, jeremiahbratton, shailu25.
Fixes #50696.

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/js/_enqueues/wp/customize/controls.js

    r60482 r60715  
    40674067         */
    40684068        addNewPage: function () {
    4069             var control = this, promise, toggle, container, input, title, select;
     4069            var control = this, promise, toggle, container, input, inputError, title, select;
    40704070
    40714071            if ( 'dropdown-pages' !== control.params.type || ! control.params.allow_addition || ! api.Menus ) {
     
    40764076            container = control.container.find( '.new-content-item-wrapper' );
    40774077            input = control.container.find( '.create-item-input' );
     4078            inputError = control.container.find('.create-item-error');
    40784079            title = input.val();
    40794080            select = control.container.find( 'select' );
    40804081
    40814082            if ( ! title ) {
    4082                 input.addClass( 'invalid' );
     4083                container.addClass( 'form-invalid' );
     4084                input.attr('aria-invalid', 'true');
     4085                input.attr('aria-describedby', inputError.attr('id'));
     4086                inputError.slideDown( 'fast' );
     4087                wp.a11y.speak( inputError.text() );
    40834088                return;
    40844089            }
    40854090
    4086             input.removeClass( 'invalid' );
     4091            container.removeClass( 'form-invalid' );
     4092            input.attr('aria-invalid', 'false');
     4093            input.removeAttr('aria-describedby');
     4094            inputError.hide();
    40874095            input.attr( 'disabled', 'disabled' );
    40884096
  • trunk/src/js/_enqueues/wp/customize/nav-menus.js

    r59948 r60715  
    662662                itemObject = dataContainer.data( 'object' ),
    663663                itemTypeLabel = dataContainer.data( 'type_label' ),
     664                inputError = container.find('.create-item-error'),
    664665                promise;
    665666
     
    672673                return;
    673674            }
    674 
    675675            if ( '' === itemName.val().trim() ) {
    676                 itemName.addClass( 'invalid' );
    677                 itemName.focus();
     676                container.addClass( 'form-invalid' );
     677                itemName.attr('aria-invalid', 'true');
     678                itemName.attr('aria-describedby', inputError.attr('id'));
     679                inputError.slideDown( 'fast' );
     680                wp.a11y.speak( inputError.text() );
    678681                return;
    679682            } else {
    680                 itemName.removeClass( 'invalid' );
     683                container.removeClass( 'form-invalid' );
     684                itemName.attr('aria-invalid', 'false');
     685                itemName.removeAttr('aria-describedby');
     686                inputError.hide();
    681687                container.find( '.accordion-section-title' ).addClass( 'loading' );
    682688            }
  • trunk/src/wp-includes/class-wp-customize-control.php

    r60668 r60715  
    647647                        <label for="create-input-<?php echo esc_attr( $this->id ); ?>"><?php _e( 'New page title' ); ?></label>
    648648                        <div class="new-content-item">
    649                             <input type="text" id="create-input-<?php echo esc_attr( $this->id ); ?>" class="create-item-input" >
     649                            <input type="text" id="create-input-<?php echo esc_attr( $this->id ); ?>" class="create-item-input form-required">
    650650                            <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
    651651                        </div>
     652                        <span id="create-input-<?php echo esc_attr( $this->id ); ?>-error" class="create-item-error error-message" style="display: none;"><?php _e( 'Please enter a page title' ); ?></span>
     653
    652654                    </div>
    653655                <?php endif; ?>
  • trunk/src/wp-includes/class-wp-customize-nav-menus.php

    r60681 r60715  
    12381238                            <label for="<?php echo esc_attr( 'create-item-input-' . $available_item_type['object'] ); ?>"><?php echo esc_html( $post_type_obj->labels->add_new_item ); ?></label>
    12391239                            <div class="new-content-item">
    1240                                 <input type="text" id="<?php echo esc_attr( 'create-item-input-' . $available_item_type['object'] ); ?>" class="create-item-input">
     1240                                <input type="text" id="<?php echo esc_attr( 'create-item-input-' . $available_item_type['object'] ); ?>" class="create-item-input form-required">
    12411241                                <button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
    12421242                            </div>
     1243                            <span id="create-input-<?php echo esc_attr( $available_item_type['object'] ); ?>-error" class="create-item-error error-message" style="display: none;"><?php _e( 'Please enter an item title' ); ?></span>
     1244
    12431245                        </div>
    12441246                    <?php endif; ?>
Note: See TracChangeset for help on using the changeset viewer.