Skip to content
Closed
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
Autocomplete: wrap announce in useCallback
  • Loading branch information
chad1008 committed Jun 15, 2022
commit 760c529193eaf6f1151af9a1cd7bdc8718b58943
41 changes: 22 additions & 19 deletions packages/components/src/autocomplete/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,30 @@ function useAutocomplete( {
setAutocompleterUI( null );
}

function announce( options ) {
if ( ! debouncedSpeak ) {
return;
}
if ( !! options.length ) {
debouncedSpeak(
sprintf(
/* translators: %d: number of results. */
_n(
'%d result found, use up and down arrow keys to navigate.',
'%d results found, use up and down arrow keys to navigate.',
const announce = useCallback(
( options ) => {
if ( ! debouncedSpeak ) {
return;
}
if ( !! options.length ) {
debouncedSpeak(
sprintf(
/* translators: %d: number of results. */
_n(
'%d result found, use up and down arrow keys to navigate.',
'%d results found, use up and down arrow keys to navigate.',
options.length
),
options.length
),
options.length
),
'assertive'
);
} else {
debouncedSpeak( __( 'No results.' ), 'assertive' );
}
}
'assertive'
);
} else {
debouncedSpeak( __( 'No results.' ), 'assertive' );
}
},
[ debouncedSpeak ]
);

/**
* Load options for an autocompleter.
Expand Down