Should Thymeleaf provide an accessibility dialect that auto‑injects ARIA attributes?
0 reputation · 07 Mar 2024, 12:14 UTC
0 reputation · 07 Mar 2024, 12:14 UTC
Goal: Evaluate whether Thymeleaf should introduce an optional accessibility dialect that automatically injects ARIA roles, labels, and live‑region attributes based on the semantic meaning of HTML5 elements used in templates.
Currently, developers must add ARIA attributes manually with th:attr, th:attrprepend, or th:attrappend, which can lead to inconsistent or missing accessibility markup. An unresolved decision is whether to adopt a convention‑over‑configuration approach (auto‑generation) or keep the explicit, developer‑driven method, considering potential version conflicts with existing Thymeleaf extras and the need for build‑tool and IDE support. What design principles should govern such a dialect? How would it coexist with existing Thymeleaf‑extras modules? What impact would automatic ARIA injection have on backward compatibility and existing projects?
30775 reputation · 07 Mar 2024, 13:40 UTC
Thymeleaf should offer an accessibility dialect as an opt-in module, not as silent auto-injection. The safest approach is a dedicated processor that adds ARIA only when developers haven't already specified it, preserving explicit control and avoiding conflicts with native HTML semantics.
ARIA's first rule states that native HTML elements already convey accessibility information. Blindly injecting role, aria-label, or aria-describedby can create redundancy or even contradictions. For example, a <button> already has an implicit role="button"; adding another role could confuse assistive technologies.
SpringTemplateEngine or TemplateEngine configuration. Never enable it by default.banner, main, navigation) that have no native equivalent, not on elements that already carry meaning.Following the thymeleaf-extras pattern keeps the feature isolated. Create a separate artifact (e.g., thymeleaf-extras-a11y) with its own dialect prefix (a11y: or similar). This avoids processor-ordering surprises and allows projects to adopt it gradually.
Because the dialect is opt-in, existing templates remain unchanged. The only risk is accidental registration—mitigate by requiring explicit bean registration in Spring or explicit dialect addition in standalone engines.
IAttributeTagProcessor to intercept specific elements (e.g., <img> without alt, <input> without aria-label).axe-core or similar tools to verify injected attributes improve, rather than harm, accessibility.Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.