swarm-ui: say 1 hit, not 1 hits, in a box's screen-reader label
This commit is contained in:
parent
404d8334aa
commit
81fd4466a5
2 changed files with 8 additions and 6 deletions
|
|
@ -13,6 +13,11 @@ const PAD = 10;
|
||||||
// The long kind name would run into the aside beside it.
|
// The long kind name would run into the aside beside it.
|
||||||
const SHORT_KIND: Record<string, string> = { request_reviewer: "reviewer" };
|
const SHORT_KIND: Record<string, string> = { request_reviewer: "reviewer" };
|
||||||
|
|
||||||
|
// "1 hit", "0 hits": how the box says how many events reached it.
|
||||||
|
export function hitsText(hits: number): string {
|
||||||
|
return `${hits} ${hits === 1 ? "hit" : "hits"}`;
|
||||||
|
}
|
||||||
|
|
||||||
export function BoxFace({
|
export function BoxFace({
|
||||||
kind,
|
kind,
|
||||||
text,
|
text,
|
||||||
|
|
@ -26,10 +31,7 @@ export function BoxFace({
|
||||||
// The events of the last dry run that reached the node, when one covers it.
|
// The events of the last dry run that reached the node, when one covers it.
|
||||||
hits?: number;
|
hits?: number;
|
||||||
}) {
|
}) {
|
||||||
const aside = [
|
const aside = [order, hits === undefined ? undefined : hitsText(hits)]
|
||||||
order,
|
|
||||||
hits === undefined ? undefined : `${hits} ${hits === 1 ? "hit" : "hits"}`,
|
|
||||||
]
|
|
||||||
.filter((part) => part !== undefined)
|
.filter((part) => part !== undefined)
|
||||||
.join(" · ");
|
.join(" · ");
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ import {
|
||||||
type Edit,
|
type Edit,
|
||||||
type Limits,
|
type Limits,
|
||||||
} from "./FlowDraft.js";
|
} from "./FlowDraft.js";
|
||||||
import { BoxFace } from "./FlowBox.js";
|
import { BoxFace, hitsText } from "./FlowBox.js";
|
||||||
import { layoutFlow, neighbour, nodeAt } from "./FlowLayout.js";
|
import { layoutFlow, neighbour, nodeAt } from "./FlowLayout.js";
|
||||||
import { describeNode, ordinal, type Flow } from "./FlowTypes.js";
|
import { describeNode, ordinal, type Flow } from "./FlowTypes.js";
|
||||||
|
|
||||||
|
|
@ -341,7 +341,7 @@ export function FlowCanvas({
|
||||||
tabIndex={p.id === tabStop ? 0 : -1}
|
tabIndex={p.id === tabStop ? 0 : -1}
|
||||||
role="button"
|
role="button"
|
||||||
aria-pressed={p.id === selected}
|
aria-pressed={p.id === selected}
|
||||||
aria-label={`${node.kind} ${p.id}: ${text}${order}${hits ? `, ${hits.get(p.id) ?? 0} hits` : ""}`}
|
aria-label={`${node.kind} ${p.id}: ${text}${order}${hits ? `, ${hitsText(hits.get(p.id) ?? 0)}` : ""}`}
|
||||||
onPointerDown={(e) => {
|
onPointerDown={(e) => {
|
||||||
if (node.kind === "source") {
|
if (node.kind === "source") {
|
||||||
// The source cannot move; a press just picks it.
|
// The source cannot move; a press just picks it.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue