daf9445d3c00a9c233b0acc26981ec63d9b13245011f6b2997d93159a276c36200c11a36466a136d1720939dcb4bba532761a17258cdd9b649013ceca24fd6 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var aria$1 = require('../../../../utils/dom/aria.js');
  4. var aria = require('../../../../constants/aria.js');
  5. class SubMenu {
  6. constructor(parent, domNode) {
  7. this.parent = parent;
  8. this.domNode = domNode;
  9. this.subIndex = 0;
  10. this.subIndex = 0;
  11. this.init();
  12. }
  13. init() {
  14. this.subMenuItems = this.domNode.querySelectorAll("li");
  15. this.addListeners();
  16. }
  17. gotoSubIndex(idx) {
  18. if (idx === this.subMenuItems.length) {
  19. idx = 0;
  20. } else if (idx < 0) {
  21. idx = this.subMenuItems.length - 1;
  22. }
  23. this.subMenuItems[idx].focus();
  24. this.subIndex = idx;
  25. }
  26. addListeners() {
  27. const parentNode = this.parent.domNode;
  28. Array.prototype.forEach.call(this.subMenuItems, (el) => {
  29. el.addEventListener("keydown", (event) => {
  30. let prevDef = false;
  31. switch (event.code) {
  32. case aria.EVENT_CODE.down: {
  33. this.gotoSubIndex(this.subIndex + 1);
  34. prevDef = true;
  35. break;
  36. }
  37. case aria.EVENT_CODE.up: {
  38. this.gotoSubIndex(this.subIndex - 1);
  39. prevDef = true;
  40. break;
  41. }
  42. case aria.EVENT_CODE.tab: {
  43. aria$1.triggerEvent(parentNode, "mouseleave");
  44. break;
  45. }
  46. case aria.EVENT_CODE.enter:
  47. case aria.EVENT_CODE.numpadEnter:
  48. case aria.EVENT_CODE.space: {
  49. prevDef = true;
  50. event.currentTarget.click();
  51. break;
  52. }
  53. }
  54. if (prevDef) {
  55. event.preventDefault();
  56. event.stopPropagation();
  57. }
  58. return false;
  59. });
  60. });
  61. }
  62. }
  63. exports["default"] = SubMenu;
  64. //# sourceMappingURL=submenu.js.map