interactive-e294111f.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*!
  2. * All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  3. * See https://github.com/Esri/calcite-components/blob/master/LICENSE.md for details.
  4. * v1.0.0-beta.82
  5. */
  6. 'use strict';
  7. function noopClick() {
  8. /** noop **/
  9. }
  10. /**
  11. * This helper updates the host element to prevent keyboard interaction on its subtree and sets the appropriate aria attribute for accessibility.
  12. *
  13. * This should be used in the `componentDidRender` lifecycle hook.
  14. *
  15. * **Notes**
  16. *
  17. * * this util is not needed for simple components whose root element or elements are an interactive component (custom element or native control). For those cases, set the `disabled` props on the root components instead.
  18. * * technically, users can override `tabindex` and restore keyboard navigation, but this will be considered user error
  19. */
  20. function updateHostInteraction(component, hostIsTabbable = false) {
  21. if (component.disabled) {
  22. component.el.setAttribute("tabindex", "-1");
  23. component.el.setAttribute("aria-disabled", "true");
  24. if (component.el.contains(document.activeElement)) {
  25. document.activeElement.blur();
  26. }
  27. component.el.click = noopClick;
  28. return;
  29. }
  30. component.el.click = HTMLElement.prototype.click;
  31. if (typeof hostIsTabbable === "function") {
  32. component.el.setAttribute("tabindex", hostIsTabbable.call(component) ? "0" : "-1");
  33. }
  34. else if (hostIsTabbable === true) {
  35. component.el.setAttribute("tabindex", "0");
  36. }
  37. else if (hostIsTabbable === false) {
  38. component.el.removeAttribute("tabindex");
  39. }
  40. else ;
  41. component.el.removeAttribute("aria-disabled");
  42. }
  43. exports.updateHostInteraction = updateHostInteraction;