-
Notifications
You must be signed in to change notification settings - Fork 401
Closed
Description
a11yNumResults and a11yNumSelected called too many times
The functions a11yNumResults and a11yNumSelected are being called too many times.
From what I can gather from the docs, they should be called when either the result set changes or when the selection set changes, respectively, they they should only be called once when the change occurs.
Steps to reproduce
Using the following typeahead:
- open the page after dropping it into a new react project
- type the letter "c" into the input
- immediately switch to the javascript console and examine the log; you can clearly see the a11yNumResults function being called twice
This produces duplicate screen reader announcements -- very annoying!
expected behavior
- log should only contain one message
- screen reader should only announce number of matches once each time match set changes
<Typeahead
emptyLabel=""
//a11yNumSelected={() => ""}
a11yNumResults={(results) => {
let n = results.length;
console.log (`a11yNumResults: ${n}`);
return `${n.toString()} matches.`;
}}
onChange={(selected) => {
this.setState({selected})
}}
options={["chocolate", "vanilla", "strawberry", "coconut"]}
minLength={1}
inputProps={{"aria-label": "Choose your favorite flavor:"}}
placeholder="Choose your favorite flavor:"
/>