Skip to content

Commit f269519

Browse files
committed
Extend UX changes to also cover Add New in nav menus
1 parent d84b835 commit f269519

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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-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)