Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/js/_enqueues/lib/nav-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,14 @@
});

$('.categorychecklist', panel).html( $items );
wp.a11y.speak( wp.i18n.sprintf( wp.i18n.__( '%d Search Results Found' ), $items.length ), 'assertive' );
wp.a11y.speak(
wp.i18n.sprintf(
/* translators: %d: Number of search results found. */
wp.i18n._n( '%d result found.', '%d results found.', $items.length ),
$items.length
),
'assertive'
);
$( '.spinner', panel ).removeClass( 'is-active' );
wrapper.removeClass( 'has-no-menu-item' );

Expand Down
24 changes: 24 additions & 0 deletions tests/qunit/wp-admin/js/nav-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,29 @@

} );

QUnit.test( 'Quick search announces the number of results with the right plural form.', function( assert ) {
var spoken = [],
$wrapper = $( '<div class="accordion-section-content"><div class="tabs-panel"><ul class="categorychecklist"></ul></div><p class="button-controls"><input type="checkbox" class="select-all" /></p></div>' ),
$panel = $wrapper.find( '.tabs-panel' ),
a11y,
speak;

// Mock wp.a11y.speak() to record what is announced.
window.wp = window.wp || {};
a11y = window.wp.a11y = window.wp.a11y || {};
speak = a11y.speak;
a11y.speak = function( message ) {
spoken.push( message );
};

try {
wpNavMenu.processQuickSearchQueryResponse( '<li>First</li>', {}, $panel );
wpNavMenu.processQuickSearchQueryResponse( '<li>First</li><li>Second</li>', {}, $panel );
} finally {
a11y.speak = speak;
}

assert.deepEqual( spoken, [ '1 result found.', '2 results found.' ] );
} );

} )( window.QUnit, jQuery );
Loading