dropdown-item.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var rovingFocusItem = require('../../roving-focus-group/src/roving-focus-item.js');
  5. var dropdownItemImpl = require('./dropdown-item-impl.js');
  6. var useDropdown = require('./useDropdown.js');
  7. var dropdown = require('./dropdown.js');
  8. var tokens = require('./tokens.js');
  9. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  10. var event = require('../../../utils/dom/event.js');
  11. const _sfc_main = vue.defineComponent({
  12. name: "ElDropdownItem",
  13. components: {
  14. ElRovingFocusItem: rovingFocusItem["default"],
  15. ElDropdownItemImpl: dropdownItemImpl["default"]
  16. },
  17. inheritAttrs: false,
  18. props: dropdown.dropdownItemProps,
  19. emits: ["pointermove", "pointerleave", "click"],
  20. setup(props, { emit, attrs }) {
  21. const { elDropdown } = useDropdown.useDropdown();
  22. const _instance = vue.getCurrentInstance();
  23. const { onItemEnter, onItemLeave } = vue.inject(
  24. tokens.DROPDOWN_INJECTION_KEY,
  25. void 0
  26. );
  27. const handlePointerMove = event.composeEventHandlers(
  28. (e) => {
  29. emit("pointermove", e);
  30. return e.defaultPrevented;
  31. },
  32. event.whenMouse((e) => {
  33. if (props.disabled) {
  34. onItemLeave(e);
  35. return;
  36. }
  37. const target = e.currentTarget;
  38. if (target === document.activeElement || target.contains(document.activeElement)) {
  39. return;
  40. }
  41. onItemEnter(e);
  42. if (!e.defaultPrevented) {
  43. target == null ? void 0 : target.focus({
  44. preventScroll: true
  45. });
  46. }
  47. })
  48. );
  49. const handlePointerLeave = event.composeEventHandlers((e) => {
  50. emit("pointerleave", e);
  51. return e.defaultPrevented;
  52. }, event.whenMouse(onItemLeave));
  53. const handleClick = event.composeEventHandlers(
  54. (e) => {
  55. if (props.disabled) {
  56. return;
  57. }
  58. emit("click", e);
  59. return e.type !== "keydown" && e.defaultPrevented;
  60. },
  61. (e) => {
  62. var _a, _b, _c;
  63. if (props.disabled) {
  64. e.stopImmediatePropagation();
  65. return;
  66. }
  67. if ((_a = elDropdown == null ? void 0 : elDropdown.hideOnClick) == null ? void 0 : _a.value) {
  68. (_b = elDropdown.handleClick) == null ? void 0 : _b.call(elDropdown);
  69. }
  70. (_c = elDropdown.commandHandler) == null ? void 0 : _c.call(elDropdown, props.command, _instance, e);
  71. }
  72. );
  73. const propsAndAttrs = vue.computed(() => ({ ...props, ...attrs }));
  74. return {
  75. handleClick,
  76. handlePointerMove,
  77. handlePointerLeave,
  78. propsAndAttrs
  79. };
  80. }
  81. });
  82. function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
  83. const _component_el_dropdown_item_impl = vue.resolveComponent("el-dropdown-item-impl");
  84. const _component_el_roving_focus_item = vue.resolveComponent("el-roving-focus-item");
  85. return vue.openBlock(), vue.createBlock(_component_el_roving_focus_item, {
  86. focusable: !_ctx.disabled
  87. }, {
  88. default: vue.withCtx(() => [
  89. vue.createVNode(_component_el_dropdown_item_impl, vue.mergeProps(_ctx.propsAndAttrs, {
  90. onPointerleave: _ctx.handlePointerLeave,
  91. onPointermove: _ctx.handlePointerMove,
  92. onClickimpl: _ctx.handleClick
  93. }), vue.createSlots({
  94. default: vue.withCtx(() => [
  95. vue.renderSlot(_ctx.$slots, "default")
  96. ]),
  97. _: 2
  98. }, [
  99. _ctx.$slots.icon ? {
  100. name: "icon",
  101. fn: vue.withCtx(() => [
  102. vue.renderSlot(_ctx.$slots, "icon")
  103. ]),
  104. key: "0"
  105. } : void 0
  106. ]), 1040, ["onPointerleave", "onPointermove", "onClickimpl"])
  107. ]),
  108. _: 3
  109. }, 8, ["focusable"]);
  110. }
  111. var DropdownItem = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "/home/runner/work/element-plus/element-plus/packages/components/dropdown/src/dropdown-item.vue"]]);
  112. exports["default"] = DropdownItem;
  113. //# sourceMappingURL=dropdown-item.js.map