Skip to content

Build your personal knowledge base with Trilium Notes

client/context help: fix an issue

Adorian Dorane5c297af959e
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index dab918a9d3..53514ad81b 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3119,7 +3119,8 @@
"dismiss": "Dismiss"
},
"contextual_help": {
- "label": "Help: {{- message}}"
+ "label": "Help: {{- message}}",
+ "sheet_label": "Help"
},
"settings": {
"related_settings": "Related settings",
diff --git a/apps/client/src/widgets/react/ContextualHelp.spec.tsx b/apps/client/src/widgets/react/ContextualHelp.spec.tsx
index c8048ca4fc..2d804ea0d1 100644
--- a/apps/client/src/widgets/react/ContextualHelp.spec.tsx
+++ b/apps/client/src/widgets/react/ContextualHelp.spec.tsx
@@ -23,8 +23,8 @@ vi.mock("../../services/utils", async (importOriginal) => ({
// The sheet is the app's own modal, which on a phone every dialog already is; what matters here is
// that the message is handed to one, and only once the icon has been tapped.
vi.mock("./Modal", () => ({
- default: ({ children, show }: { children: ComponentChildren, show: boolean }) => (
- show ? <div className="sheet-stub">{children}</div> : null
+ default: ({ children, show, ariaLabel }: { children: ComponentChildren, show: boolean, ariaLabel?: string }) => (
+ show ? <div className="sheet-stub" role="dialog" aria-label={ariaLabel}>{children}</div> : null
)
}));
@@ -140,7 +140,12 @@ describe("ContextualHelp", () => {
expect(span?.getAttribute("aria-haspopup")).toBe("dialog");
expect(press(span, "Enter")).toBe(true);
- expect(document.body.querySelector(".sheet-stub")?.textContent).toBe("What this figure covers.");
+
+ const sheet = document.body.querySelector(".sheet-stub");
+ expect(sheet?.textContent).toBe("What this figure covers.");
+ // Named, since it carries no title of its own: an unnamed dialog is announced as nothing
+ // more than "dialog", leaving the reader to work out what has just opened.
+ expect(sheet?.getAttribute("aria-label")).toBe("contextual_help.sheet_label()");
});
});
diff --git a/apps/client/src/widgets/react/ContextualHelp.tsx b/apps/client/src/widgets/react/ContextualHelp.tsx
index 81e2e399a1..0b927f3290 100644
--- a/apps/client/src/widgets/react/ContextualHelp.tsx
+++ b/apps/client/src/widgets/react/ContextualHelp.tsx
@@ -87,6 +87,10 @@ function TappedHelp({ helpMessage }: ContextualHelpProps) {
show={shown}
onHidden={() => setShown(false)}
stackable
+ // It carries no title — one sentence needs no heading over it — so without this
+ // a screen reader would announce it as an unnamed dialog and leave the reader
+ // to work out what had just opened.
+ ariaLabel={t("contextual_help.sheet_label")}
>
{helpMessage}
</Modal>
diff --git a/apps/client/src/widgets/react/Modal.tsx b/apps/client/src/widgets/react/Modal.tsx
index 771b69ee69..9584c3df29 100644
--- a/apps/client/src/widgets/react/Modal.tsx
+++ b/apps/client/src/widgets/react/Modal.tsx
@@ -99,9 +99,15 @@ export interface ModalProps {
* Indicates if the dialog will be displayed as a full page on mobile devices.
*/
isFullPageOnMobile?: boolean;
+ /**
+ * What assistive technology announces the dialog as, for a dialog whose {@link title} is not a
+ * name it can read — one shown without a title at all, above all, which would otherwise be
+ * announced as nothing but "dialog".
+ */
+ ariaLabel?: string;
}
-export default function Modal({ children, className, size, title, customTitleBarButtons: titleBarButtons, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus, sidebar, hideSidebarHeader, isFullPageOnMobile }: ModalProps) {
+export default function Modal({ children, className, size, title, customTitleBarButtons: titleBarButtons, header, footer, footerStyle, footerAlignment, onShown, onSubmit, helpPageId, minWidth, maxWidth, zIndex, scrollable, onHidden, modalRef: externalModalRef, formRef, bodyStyle, show, stackable, keepInDom, noFocus, sidebar, hideSidebarHeader, isFullPageOnMobile, ariaLabel }: ModalProps) {
const modalRef = useSyncedRef<HTMLDivElement>(externalModalRef);
const modalInstanceRef = useRef<BootstrapModal>();
const elementToFocus = useRef<Element | null>();
@@ -173,7 +179,7 @@ export default function Modal({ children, className, size, title, customTitleBar
}, [maxWidth, minWidth]);
return (
- <div className={`modal fade mx-auto ${className}`} tabIndex={-1} style={dialogStyle} role="dialog" ref={modalRef}>
+ <div className={`modal fade mx-auto ${className}`} tabIndex={-1} style={dialogStyle} role="dialog" aria-label={ariaLabel} ref={modalRef}>
{(show || keepInDom) && <ContainerVisibilityContext.Provider value={show}><div className={clsx("modal-dialog", `modal-${size}`, {"modal-dialog-scrollable": scrollable, "modal-dialog-full-page-on-mobile": isFullPageOnMobile, "modal-content-with-sidebar": sidebar})} style={documentStyle} role="document">
<div className={clsx("modal-content", sidebar && "modal-content-with-sidebar")}>
{sidebar && <div className="modal-sidebar">