dropdown-item.mjs 3.9 KB

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