Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): announce the selected option of a segmented choice

Elian Dorandb0bb3353d46
diff --git a/apps/client/src/widgets/dialogs/content_embed.spec.tsx b/apps/client/src/widgets/dialogs/content_embed.spec.tsx
index ee35b5e6ac..2a08511def 100644
--- a/apps/client/src/widgets/dialogs/content_embed.spec.tsx
+++ b/apps/client/src/widgets/dialogs/content_embed.spec.tsx
@@ -63,8 +63,8 @@ describe("ContentEmbedDialog", () => {
}
function checkedSize() {
- const active = sizeButtons().filter((button) => button.classList.contains("active"));
- if (active.length !== 1) throw new Error(`${active.length} box sizes are active.`);
+ const active = sizeButtons().filter((button) => button.getAttribute("aria-pressed") === "true");
+ if (active.length !== 1) throw new Error(`${active.length} box sizes are pressed.`);
return /^include_note\.size_(\w+)$/.exec(active[0]?.textContent?.trim() ?? "")?.[1];
}
diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsx
index bd3478cdfb..e178dda7d5 100644
--- a/apps/client/src/widgets/react/Button.tsx
+++ b/apps/client/src/widgets/react/Button.tsx
@@ -40,6 +40,8 @@ export interface ButtonProps {
title?: string;
/** Why the button is off, shown on hover while `disabled`. Ignored otherwise. */
disabledTooltip?: string;
+ /** Marks a toggle button as on or off for assistive technology. */
+ "aria-pressed"?: boolean;
}
function Button({ name, buttonRef, className, text, onClick, keyboardShortcut, icon, kind, disabled, disabledTooltip, size, style, triggerCommand, ...restProps }: ButtonProps) {
diff --git a/apps/client/src/widgets/react/SegmentedChoice.spec.tsx b/apps/client/src/widgets/react/SegmentedChoice.spec.tsx
index ee410b2e18..d41886cb2f 100644
--- a/apps/client/src/widgets/react/SegmentedChoice.spec.tsx
+++ b/apps/client/src/widgets/react/SegmentedChoice.spec.tsx
@@ -66,6 +66,8 @@ describe("SegmentedChoice", () => {
const buttons = [ ...container.querySelectorAll("button") ];
expect(buttons.map((button) => button.textContent?.trim())).toStrictEqual([ "Yours", "System" ]);
expect(buttons.map((button) => button.classList.contains("active"))).toStrictEqual([ false, true ]);
+ expect(buttons.map((button) => button.getAttribute("aria-pressed")))
+ .toStrictEqual([ "false", "true" ]);
});
it("shows a count as a badge beside the name rather than inside it", () => {
diff --git a/apps/client/src/widgets/react/SegmentedChoice.tsx b/apps/client/src/widgets/react/SegmentedChoice.tsx
index 1f8e1a35a9..747506a745 100644
--- a/apps/client/src/widgets/react/SegmentedChoice.tsx
+++ b/apps/client/src/widgets/react/SegmentedChoice.tsx
@@ -86,6 +86,7 @@ export default function SegmentedChoice<T extends string>({ options, currentValu
title={title}
size="small"
disabled={disabled}
+ aria-pressed={currentValue === value}
className={clsx(currentValue === value && "active", {
"tn-segmented-choice-with-glyph": glyph
})}