Skip to content
ERPForAll DocsDevelopment

    Accessibility and runtime strings

    Import DOM controllers from @erpforall/elang. Create them after mounting, and release them when the owning view closes. Controllers do not infer roles, labels, selection or business actions. Native controls keep their own Enter/Space behavior.

    import { createFocusTrap, createRovingTabindex, LiveRegion, createTranslator } from "@erpforall/elang";
    const trap = createFocusTrap(dialogElement, { onEscape: closeDialog });
    // The modal owner also makes the background inert and removes it on close.
    const tabs = createRovingTabindex(tablistElement, {
    items: () => [...tablistElement.querySelectorAll<HTMLButtonElement>('[role="tab"]')],
    orientation: "horizontal",
    });
    // Call after the caller changes the item collection or availability.
    tabs.refresh();
    const announcements = new LiveRegion(appElement);
    announcements.announce("Saved"); // polite by default; assertive for urgent errors
    // Snapshot the user's language and trusted catalogue at app/session creation.
    const { _t } = createTranslator({ language: userLanguage, catalogue });
    const label = _t("Hello %s", displayName);
    // On disposal:
    trap.dispose(); tabs.dispose(); announcements.destroy();

    For role="menu" dropdowns (such as action menus, cog menus, navbar overflow lists, breadcrumbs collapsed trails, and debug menus), attachMenuDropdown manages roving focus across menuitems with arrow keys (ArrowDown, ArrowUp, Home, End), Escape dismissal returning focus to the trigger button, Tab key closing, outside click dismissal, and aria-expanded synchronization.

    Only en_US is admitted in B0. Other languages fail with an error saying language selection is not available yet. Missing catalogue terms fall back to their source text. Module-scoped lookup uses translator.forModule("my_addon"). Named substitutions use _t("Hello %(name)s", {name: displayName}). Catalogue data is snapshotted and bounded; missing substitution values fail. Returned plain strings must render as text. If an argument is genuine Markup, the result is Markup and all other text, including the format string, is escaped. Never insert plain translation strings as HTML. Compiler extraction/translation and RTL remain UI5-DONE sibling deliveries.

    For Vitest import auditComponent from @erpforall/elang/testing and await it with a connected mounted component root. It runs axe-core with color contrast disabled because jsdom cannot measure rendering. Use await auditPage(page) with a Playwright Page for a complete rendered document audit including active overlays and contrast. Run audits after opening each hidden menu/dialog. Both helpers throw on serious or critical violations and return the complete engine result for other findings. Injection/engine errors propagate. The testing entry point and axe-core are dev-only; never import it from a view or runtime module. Automated audits do not prove screen-reader speech, keyboard correctness or complete WCAG conformance.

    LiveRegion is also a canonical service class: register with env.services.add(LiveRegion) before startup, then resolve with env.services.get(LiveRegion) or useService(LiveRegion). Its default service root is document.body. The app owner calls destroy() during teardown; the container does not implicitly dispose service instances.

    Catalogue admission permits at most 1024 modules (names of 1–256 UTF-16 units), 100000 terms and a 16 MiB aggregate charge. The charge is twice each term’s source and translation lengths plus 64 per term; twice each module name’s length plus 128 per module. These are admission accounting units, not measured heap bytes. Source strings are limited to 65536 units and formatted output to 1048576 units.

    createHotkeyController(root, {bindings, blocked, report}) registers a disposable view owner. Supply a synchronous array of HotkeyBinding declarations; it is validated on creation, refresh and dispatch. A DOM binding focuses and clicks its existing target. A callback binding runs run() and reports throws and rejected promises through report. Keep that error sink alive after view disposal.

    import { createHotkeyController, createHotkeyBoundary } from "@erpforall/elang";
    const shortcuts = createHotkeyController(appElement, {
    bindings: () => [{kind: "dom", chord: "alt+x", target: executeButton}],
    blocked: () => operationPending,
    report: reportError,
    });
    const overlayKeys = createHotkeyBoundary(dialogElement, {
    onEscape: closeDialog,
    report: reportError,
    });
    // After replacing controls, drop obsolete hints and validate the new collection.
    shortcuts.refresh();
    // On close/unmount (both operations are idempotent):
    overlayKeys.dispose(); shortcuts.dispose();

    Chords use optional modifiers in order ctrl+alt+meta+shift+ and a lowercase letter/digit or escape/enter. Invalid options and declarations throw UIError with code: "value"; refreshing a disposed controller is a usage error. Controllers allow at most 256 bindings each, with 128 controllers and 32 exclusive boundaries per document; chord/hint text is at most 32 UTF-16 units. These are admission limits, not measured heap figures. Targets must belong to the root’s document. A dynamic supplier failure reports to its owner and aborts the event.

    Only the active exclusive overlay receives shortcuts. An unmatched or blocked modal does not pass commands to the page behind it. A duplicate eligible chord reports one error and activates nothing. Element/document handlers may consume keys before shared dispatch at window bubbling; Escape belongs to one scope per event. Boundary Escape is allowed in editable controls, is nonrepeating and is suppressed during composition. An explicit conflicting Escape binding is an error.

    Default bindings exclude editable targets and repeats; a declaration can explicitly set allowEditable or allowRepeat. Composition sessions, isComposing, AltGraph and consumed events always win. DOM eligibility excludes hidden, inert, disabled, aria-disabled, disconnected and collapsed controls. Alt hints are text-only, aria-hidden and cleaned on release, blur, visibility loss, mutation and disposal. Native Enter/Space and editor-local keyboard behavior remain with their controls.