I am implementing a search box. One of the scenarios is that the total count of results must be announced. To achieve this I put the <p>
tag inside of an aria-live
region, and it announces it as expected.
Expected scenario:
User types a string --> hits enter --> results appear and string is announced.
The edge case is if the user hits enter twice.
If the user presses enter again without any changes, nothing is updated since the count is still the same and nothing is announced.
I tried using this on enter click:
if (document.getElementById("header")) {
const currentText: string = document.getElementById("header").innerHTML;
document.getElementById("search-header").innerHTML = "";
document.getElementById("search-header").innerHTML = currentText;
}
But, it still did not announce.
Is there another way to accomplish this?
I faced the same issue. I modified the string with the addition of period, in the end, if the same string is added again to the aira-live div.
I compared the new text value with the existing one in tag, if the value is same then I added period (.) to the incoming string.