Skip to content

Commit

Permalink
Fix: Inserter Search Results Not Announcing (#10755)
Browse files Browse the repository at this point in the history
* added functionality to get the result count and announcer it in the live region

* chore: Tweak variable names/readability

* Sort props
  • Loading branch information
Luciaisacomputer authored and tofumatt committed Oct 23, 2018
1 parent a563dc7 commit 9a80b98
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions packages/editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import scrollIntoView from 'dom-scroll-into-view';
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { __, _n, sprintf } from '@wordpress/i18n';
import { Component, findDOMNode, createRef } from '@wordpress/element';
import { withSpokenMessages, PanelBody } from '@wordpress/components';
import { getCategories, isReusableBlock } from '@wordpress/blocks';
Expand Down Expand Up @@ -162,7 +162,7 @@ export class InserterMenu extends Component {
}

filter( filterValue = '' ) {
const { items, rootChildBlocks } = this.props;
const { debouncedSpeak, items, rootChildBlocks } = this.props;
const filteredItems = searchItems( items, filterValue );

const childItems = filter( filteredItems, ( { name } ) => includes( rootChildBlocks, name ) );
Expand Down Expand Up @@ -205,6 +205,17 @@ export class InserterMenu extends Component {
itemsPerCategory,
openPanels,
} );

const resultCount = Object.keys( itemsPerCategory ).reduce( ( accumulator, currentCategorySlug ) => {
return accumulator + itemsPerCategory[ currentCategorySlug ].length;
}, 0 );

const resultsFoundMessage = sprintf(
_n( '%d result found.', '%d results found.', resultCount ),
resultCount
);

debouncedSpeak( resultsFoundMessage, 'assertive' );
}

render() {
Expand Down

0 comments on commit 9a80b98

Please sign in to comment.