interactive-32293bca.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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.97
  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. * @param component
  21. * @param hostIsTabbable
  22. */
  23. function updateHostInteraction(component, hostIsTabbable = false) {
  24. if (component.disabled) {
  25. component.el.setAttribute("tabindex", "-1");
  26. component.el.setAttribute("aria-disabled", "true");
  27. if (component.el.contains(document.activeElement)) {
  28. document.activeElement.blur();
  29. }
  30. component.el.click = noopClick;
  31. return;
  32. }
  33. component.el.click = HTMLElement.prototype.click;
  34. if (typeof hostIsTabbable === "function") {
  35. component.el.setAttribute("tabindex", hostIsTabbable.call(component) ? "0" : "-1");
  36. }
  37. else if (hostIsTabbable === true) {
  38. component.el.setAttribute("tabindex", "0");
  39. }
  40. else if (hostIsTabbable === false) {
  41. component.el.removeAttribute("tabindex");
  42. }
  43. else ;
  44. component.el.removeAttribute("aria-disabled");
  45. }
  46. exports.updateHostInteraction = updateHostInteraction;