Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Global Styles: do not announce a result when the block list is empty
An empty list renders its message as the wrapper's only child, so the
child count read for the announcement was 1 and a screen reader heard
"1 result found." alongside "You haven't customized any blocks yet."

Reachable on the filter's own path, where the list can be empty with no
search term, so count the children only when there are results.
  • Loading branch information
ramonjd committed Aug 18, 2026
commit 818fff543a9f8ca05d46fd4ca539d36014903504
9 changes: 7 additions & 2 deletions packages/global-styles-ui/src/screen-block-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ function BlockList( { filterValue, styleFilter }: BlockListProps ) {
const blockTypesListRef = useRef< HTMLDivElement >( null );

// Announce result count on change
const hasResults = filteredBlockTypes.length > 0;
useEffect( () => {
if ( ! filterValue && styleFilter === 'all' ) {
return;
Expand All @@ -255,14 +256,18 @@ function BlockList( { filterValue, styleFilter }: BlockListProps ) {
// fragile and depends on the number of rendered elements of `BlockMenuItem`,
// which is now one.
// @see https://github.com/WordPress/gutenberg/pull/39117#discussion_r816022116
const count = blockTypesListRef.current?.childElementCount || 0;
// An empty list renders the empty state message as its only child, so
// only count the children when there are results to count.
const count = hasResults
? blockTypesListRef.current?.childElementCount || 0
: 0;
const resultsFoundMessage = sprintf(
/* translators: %d: number of results. */
_n( '%d result found.', '%d results found.', count ),
count
);
debouncedSpeak( resultsFoundMessage, 'polite' );
}, [ filterValue, styleFilter, debouncedSpeak ] );
}, [ filterValue, styleFilter, hasResults, debouncedSpeak ] );

return (
<div
Expand Down
Loading