I am building a simple client-side text search on a list of items, where I want the screenreader to read how many items are found. For example if your search return two items, I want the screenreader to announce: "Two results found". To test this I am using VoiceOver.
The issue I am facing is that the announcement of this message is almost always interrupted by the screenreader reading the text your are typing in the element, causing the user to (partially) miss the message.
This is the markup for the aria-live area:
<div aria-live="assertive" aria-relevant="all" class="sr-only border-r">
<template v-if="searchTerm.length">
<span v-if="filteredItems.length === 1">
Found 1 result
</span>
<span v-else-if="filteredItems.length > 1">
Found {{ filteredItems.length }} results
</span>
<span v-else>No searchresults</span>
</template>
</div>
I have tried implementing this with a aria-role=status, which gave me the same results. I have also implemented the same thing with a debounce on the input. That only makes the issue less severe, because the screenreader has a little bit more time to finish reading the text that's typed.
So how do I implement this in a way that the message is always announced completely?
See this codepen for a full code example: https://codepen.io/chrisdh/pen/BaZyXYz