accessibility.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // In this file we define a set of DOM transformations that are specifically
  2. // intended for blind screen readers.
  3. //
  4. // See https://github.com/wekan/wekan/issues/337 for the general accessibility
  5. // considerations.
  6. // Without an href, links are non-keyboard-focusable and are not presented on
  7. // blind screen readers. We default to the empty anchor `#` href.
  8. function enforceHref(attributes) {
  9. if (!_.has(attributes, 'href')) {
  10. attributes.href = '#';
  11. }
  12. return attributes;
  13. }
  14. // `title` is inconsistently used on the web, and is thus inconsistently
  15. // presented by screen readers. `aria-label`, on the other hand, is specific to
  16. // accessibility and is presented in ways that title shouldn't be.
  17. function copyTitleInAriaLabel(attributes) {
  18. if (!_.has(attributes, 'aria-label') && _.has(attributes, 'title')) {
  19. attributes['aria-label'] = attributes.title;
  20. }
  21. return attributes;
  22. }
  23. // XXX Our implementation relies on overwriting Blaze virtual DOM functions,
  24. // which is a little bit hacky -- but still reasonable with our ES6 usage. If we
  25. // end up switching to React we will probably create lower level small
  26. // components to handle that without overwriting any build-in function.
  27. const { A: superA, I: superI } = HTML;
  28. HTML.A = (attributes, ...others) => {
  29. return superA(copyTitleInAriaLabel(enforceHref(attributes)), ...others);
  30. };
  31. HTML.I = (attributes, ...others) => {
  32. return superI(copyTitleInAriaLabel(attributes), ...others);
  33. };