Skip to content

Commit 359980f

Browse files
committed
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. git-svn-id: https://develop.svn.wordpress.org/trunk@60715 602fd350-edb4-49c9-b593-d223f7449a82
1 parent afbe174 commit 359980f

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

src/js/_enqueues/wp/customize/controls.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4066,7 +4066,7 @@
40664066
* @return {void}
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 ) {
40724072
return;
@@ -4075,15 +4075,23 @@
40754075
toggle = control.container.find( '.add-new-toggle' );
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

40894097
// The menus functions add the page, publish when appropriate,

src/js/_enqueues/wp/customize/nav-menus.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@
661661
itemType = dataContainer.data( 'type' ),
662662
itemObject = dataContainer.data( 'object' ),
663663
itemTypeLabel = dataContainer.data( 'type_label' ),
664+
inputError = container.find('.create-item-error'),
664665
promise;
665666

666667
if ( ! this.currentMenuControl ) {
@@ -671,13 +672,18 @@
671672
if ( 'post_type' !== itemType ) {
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
}
683689

src/wp-includes/class-wp-customize-control.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,11 @@ protected function render_content() {
646646
<div class="new-content-item-wrapper">
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; ?>
654656
<?php

src/wp-includes/class-wp-customize-nav-menus.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1237,9 +1237,11 @@ protected function print_post_type_container( $available_item_type ) {
12371237
<div class="new-content-item-wrapper">
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; ?>
12451247
<?php endif; ?>

0 commit comments

Comments
 (0)