From 1a2991f2737dae9f51dce6559aa09c6646732702 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 25 Feb 2022 22:34:51 +0800 Subject: [PATCH] fix: mentions cannot select, close #5233 --- components/menu/src/Menu.tsx | 4 +++- components/vc-mentions/src/DropdownMenu.tsx | 16 ++++++++++++---- components/vc-mentions/src/KeywordTrigger.tsx | 5 ++--- components/vc-overflow/Overflow.tsx | 6 ++++++ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/components/menu/src/Menu.tsx b/components/menu/src/Menu.tsx index 13a1ddcd85..02982b7314 100644 --- a/components/menu/src/Menu.tsx +++ b/components/menu/src/Menu.tsx @@ -27,7 +27,7 @@ import SubMenu from './SubMenu'; import EllipsisOutlined from '@ant-design/icons-vue/EllipsisOutlined'; import { cloneElement } from '../../_util/vnode'; import { OVERFLOW_KEY, PathContext } from './hooks/useKeyPath'; -import type { FocusEventHandler } from '../../_util/EventInterface'; +import type { FocusEventHandler, MouseEventHandler } from '../../_util/EventInterface'; export const menuProps = { id: String, @@ -64,6 +64,7 @@ export const menuProps = { onClick: [Function, Array] as PropType, onFocus: Function as PropType, onBlur: Function as PropType, + onMousedown: Function as PropType, 'onUpdate:openKeys': Function as PropType<(keys: Key[]) => void>, 'onUpdate:selectedKeys': Function as PropType<(keys: Key[]) => void>, 'onUpdate:activeKey': Function as PropType<(key: Key) => void>, @@ -422,6 +423,7 @@ export default defineComponent({ <> { + clearTimeout(timeoutId); + timeoutId = setTimeout(() => { + onFocus(e); + }); + }; + onBeforeUnmount(() => { + clearTimeout(timeoutId); + }); return () => { const { prefixCls, options } = props; const activeOption = options[activeIndex.value] || {}; @@ -40,8 +49,7 @@ export default defineComponent({ const option = options.find(({ value }) => value === key); selectOption(option); }} - onBlur={onBlur} - onFocus={onFocus} + onMousedown={onMousedown} > {!loading.value && options.map((option, index) => { diff --git a/components/vc-mentions/src/KeywordTrigger.tsx b/components/vc-mentions/src/KeywordTrigger.tsx index 3bb9078be2..fde89a3dc8 100644 --- a/components/vc-mentions/src/KeywordTrigger.tsx +++ b/components/vc-mentions/src/KeywordTrigger.tsx @@ -92,9 +92,8 @@ export default defineComponent({ popupTransitionName={transitionName} builtinPlacements={BUILT_IN_PLACEMENTS} getPopupContainer={getPopupContainer} - > - {slots.default?.()} - + v-slots={{ default: slots.default }} + > ); }; }, diff --git a/components/vc-overflow/Overflow.tsx b/components/vc-overflow/Overflow.tsx index 12e84f25be..bf6f482ce0 100644 --- a/components/vc-overflow/Overflow.tsx +++ b/components/vc-overflow/Overflow.tsx @@ -2,6 +2,7 @@ import type { CSSProperties, HTMLAttributes, PropType } from 'vue'; import { computed, defineComponent, ref, watch } from 'vue'; import ResizeObserver from '../vc-resize-observer'; import classNames from '../_util/classNames'; +import type { MouseEventHandler } from '../_util/EventInterface'; import type { Key, VueNode } from '../_util/type'; import PropTypes from '../_util/vue-types'; import { OverflowContextProvider } from './context'; @@ -37,6 +38,8 @@ export interface OverflowProps extends HTMLAttributes { /** When set to `full`, ssr will render full items by default and remove at client side */ ssr?: 'full'; + + onMousedown?: MouseEventHandler; } const Overflow = defineComponent({ @@ -63,6 +66,7 @@ const Overflow = defineComponent({ onVisibleChange: Function as PropType<(visibleCount: number) => void>, /** When set to `full`, ssr will render full items by default and remove at client side */ ssr: String as PropType<'full'>, + onMousedown: Function as PropType, }, emits: ['visibleChange'], setup(props, { attrs, emit }) { @@ -247,6 +251,7 @@ const Overflow = defineComponent({ suffix, component: Component = 'div' as any, id, + onMousedown, } = props; const { class: className, style, ...restAttrs } = attrs; let suffixStyle: CSSProperties = {}; @@ -346,6 +351,7 @@ const Overflow = defineComponent({ id={id} class={classNames(!invalidate.value && prefixCls, className)} style={style} + onMousedown={onMousedown} {...restAttrs} > {mergedData.value.map(internalRenderItemNode)}