fix(ui): announce a filter bar's result count

The count beside every filter bar was a plain span, so a screen reader
heard nothing while a list narrowed, only the empty state once nothing
was left. Make it a polite status region.
This commit is contained in:
Marc-André Bombeck committed 2026-11-11 00:47:27 +01:00
1 parent 128cf55ab6
commit ee1eb921a9
2 files changed
+33 -1

No files matched your search

@@ -121,6 +121,31 @@ describe("<LabFilterRail>", () => {
expect(extractCountText(renderCount("ru", 5))).toBe("5 биомаркеров");
});
it("announces the result count as it changes while typing", () => {
const html = renderToStaticMarkup(
<I18nProvider initialLocale="en">
<LabFilterRail
filters={{}}
searchDraft="ferr"
onSearchChange={vi.fn()}
searchInputRef={{ current: null }}
onStatusChange={vi.fn()}
onCategoryChange={vi.fn()}
onFromDayChange={vi.fn()}
onToDayChange={vi.fn()}
onResetFilters={vi.fn()}
isFiltered
total={2}
/>
</I18nProvider>,
);
const count = html.match(/<span([^>]*)>2 biomarkers<\/span>/);
expect(count).not.toBeNull();
expect(count![1]).toContain('role="status"');
expect(count![1]).toContain('aria-live="polite"');
expect(count![1]).toContain('aria-atomic="true"');
});
it("shows reset button when isFiltered is true", () => {
const html = renderToStaticMarkup(
<I18nProvider initialLocale="en">
+8 -1
View File
@@ -120,8 +120,15 @@ export function FilterBar({
</Button>
)}
</div>
{/* A polite status, so a list that filters while you type says how
many results are left, not only when none are. */}
{count != null && (
<span className="text-muted-foreground text-sm tabular-nums">
<span
role="status"
aria-live="polite"
aria-atomic="true"
className="text-muted-foreground text-sm tabular-nums"
>
{count}
</span>
)}