Skip to content

Commit

Permalink
Accessiblity: Throttle search results messages in FormTokenField
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jun 26, 2017
1 parent 22d0bde commit 8253709
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions components/form-token-field/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { last, take, clone, uniq, map, difference, each, identity, some } from 'lodash';
import { last, take, clone, uniq, map, difference, each, identity, some, throttle } from 'lodash';
import classnames from 'classnames';

/**
Expand Down Expand Up @@ -46,6 +46,7 @@ class FormTokenField extends Component {
this.onInputChange = this.onInputChange.bind( this );
this.bindInput = this.bindInput.bind( this );
this.bindTokensAndInput = this.bindTokensAndInput.bind( this );
this.throlltedSpeak = throttle( this.speak.bind( this ), 1000 );
}

componentDidUpdate() {
Expand Down Expand Up @@ -190,13 +191,13 @@ class FormTokenField extends Component {
if ( showMessage ) {
const matchingSuggestions = this.getMatchingSuggestions( tokenValue );
if ( !! matchingSuggestions.length ) {
this.speak( sprintf( _n(
this.throlltedSpeak( sprintf( _n(
'%d result found, use up and down arrow keys to navigate.',
'%d results found, use up and down arrow keys to navigate.',
matchingSuggestions.length
), matchingSuggestions.length ) );
} else {
this.speak( __( 'No results.' ) );
this.throlltedSpeak( __( 'No results.' ) );
}
}
}
Expand Down

0 comments on commit 8253709

Please sign in to comment.