Skip to content

Commit 1a2991f

Browse files
committed
fix: mentions cannot select, close #5233
1 parent 1eec85f commit 1a2991f

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

components/menu/src/Menu.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import SubMenu from './SubMenu';
2727
import EllipsisOutlined from '@ant-design/icons-vue/EllipsisOutlined';
2828
import { cloneElement } from '../../_util/vnode';
2929
import { OVERFLOW_KEY, PathContext } from './hooks/useKeyPath';
30-
import type { FocusEventHandler } from '../../_util/EventInterface';
30+
import type { FocusEventHandler, MouseEventHandler } from '../../_util/EventInterface';
3131

3232
export const menuProps = {
3333
id: String,
@@ -64,6 +64,7 @@ export const menuProps = {
6464
onClick: [Function, Array] as PropType<MenuClickEventHandler>,
6565
onFocus: Function as PropType<FocusEventHandler>,
6666
onBlur: Function as PropType<FocusEventHandler>,
67+
onMousedown: Function as PropType<MouseEventHandler>,
6768
'onUpdate:openKeys': Function as PropType<(keys: Key[]) => void>,
6869
'onUpdate:selectedKeys': Function as PropType<(keys: Key[]) => void>,
6970
'onUpdate:activeKey': Function as PropType<(key: Key) => void>,
@@ -422,6 +423,7 @@ export default defineComponent({
422423
<>
423424
<Overflow
424425
{...attrs}
426+
onMousedown={props.onMousedown}
425427
prefixCls={`${prefixCls.value}-overflow`}
426428
component="ul"
427429
itemComponent={MenuItem}

components/vc-mentions/src/DropdownMenu.tsx

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Menu, { Item as MenuItem } from '../../menu';
22
import type { PropType } from 'vue';
3-
import { defineComponent, inject, ref } from 'vue';
3+
import { onBeforeUnmount, defineComponent, inject, ref } from 'vue';
44
import type { OptionProps } from './Option';
55
import MentionsContextKey from './MentionsContext';
66
import Spin from '../../spin';
@@ -22,12 +22,21 @@ export default defineComponent({
2222
setActiveIndex,
2323
selectOption,
2424
onFocus = noop,
25-
onBlur = noop,
2625
loading,
2726
} = inject(MentionsContextKey, {
2827
activeIndex: ref(),
2928
loading: ref(false),
3029
});
30+
let timeoutId: any;
31+
const onMousedown = (e: MouseEvent) => {
32+
clearTimeout(timeoutId);
33+
timeoutId = setTimeout(() => {
34+
onFocus(e);
35+
});
36+
};
37+
onBeforeUnmount(() => {
38+
clearTimeout(timeoutId);
39+
});
3140
return () => {
3241
const { prefixCls, options } = props;
3342
const activeOption = options[activeIndex.value] || {};
@@ -40,8 +49,7 @@ export default defineComponent({
4049
const option = options.find(({ value }) => value === key);
4150
selectOption(option);
4251
}}
43-
onBlur={onBlur}
44-
onFocus={onFocus}
52+
onMousedown={onMousedown}
4553
>
4654
{!loading.value &&
4755
options.map((option, index) => {

components/vc-mentions/src/KeywordTrigger.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ export default defineComponent({
9292
popupTransitionName={transitionName}
9393
builtinPlacements={BUILT_IN_PLACEMENTS}
9494
getPopupContainer={getPopupContainer}
95-
>
96-
{slots.default?.()}
97-
</Trigger>
95+
v-slots={{ default: slots.default }}
96+
></Trigger>
9897
);
9998
};
10099
},

components/vc-overflow/Overflow.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { CSSProperties, HTMLAttributes, PropType } from 'vue';
22
import { computed, defineComponent, ref, watch } from 'vue';
33
import ResizeObserver from '../vc-resize-observer';
44
import classNames from '../_util/classNames';
5+
import type { MouseEventHandler } from '../_util/EventInterface';
56
import type { Key, VueNode } from '../_util/type';
67
import PropTypes from '../_util/vue-types';
78
import { OverflowContextProvider } from './context';
@@ -37,6 +38,8 @@ export interface OverflowProps<ItemType> extends HTMLAttributes {
3738

3839
/** When set to `full`, ssr will render full items by default and remove at client side */
3940
ssr?: 'full';
41+
42+
onMousedown?: MouseEventHandler;
4043
}
4144

4245
const Overflow = defineComponent({
@@ -63,6 +66,7 @@ const Overflow = defineComponent({
6366
onVisibleChange: Function as PropType<(visibleCount: number) => void>,
6467
/** When set to `full`, ssr will render full items by default and remove at client side */
6568
ssr: String as PropType<'full'>,
69+
onMousedown: Function as PropType<MouseEventHandler>,
6670
},
6771
emits: ['visibleChange'],
6872
setup(props, { attrs, emit }) {
@@ -247,6 +251,7 @@ const Overflow = defineComponent({
247251
suffix,
248252
component: Component = 'div' as any,
249253
id,
254+
onMousedown,
250255
} = props;
251256
const { class: className, style, ...restAttrs } = attrs;
252257
let suffixStyle: CSSProperties = {};
@@ -346,6 +351,7 @@ const Overflow = defineComponent({
346351
id={id}
347352
class={classNames(!invalidate.value && prefixCls, className)}
348353
style={style}
354+
onMousedown={onMousedown}
349355
{...restAttrs}
350356
>
351357
{mergedData.value.map(internalRenderItemNode)}

0 commit comments

Comments
 (0)