fix: mentions cannot select, close #5233
parent
c7492a0b59
commit
f0bc380527
|
@ -27,7 +27,7 @@ import SubMenu from './SubMenu';
|
||||||
import EllipsisOutlined from '@ant-design/icons-vue/EllipsisOutlined';
|
import EllipsisOutlined from '@ant-design/icons-vue/EllipsisOutlined';
|
||||||
import { cloneElement } from '../../_util/vnode';
|
import { cloneElement } from '../../_util/vnode';
|
||||||
import { OVERFLOW_KEY, PathContext } from './hooks/useKeyPath';
|
import { OVERFLOW_KEY, PathContext } from './hooks/useKeyPath';
|
||||||
import type { FocusEventHandler } from '../../_util/EventInterface';
|
import type { FocusEventHandler, MouseEventHandler } from '../../_util/EventInterface';
|
||||||
|
|
||||||
export const menuProps = {
|
export const menuProps = {
|
||||||
id: String,
|
id: String,
|
||||||
|
@ -64,6 +64,7 @@ export const menuProps = {
|
||||||
onClick: [Function, Array] as PropType<MenuClickEventHandler>,
|
onClick: [Function, Array] as PropType<MenuClickEventHandler>,
|
||||||
onFocus: Function as PropType<FocusEventHandler>,
|
onFocus: Function as PropType<FocusEventHandler>,
|
||||||
onBlur: Function as PropType<FocusEventHandler>,
|
onBlur: Function as PropType<FocusEventHandler>,
|
||||||
|
onMousedown: Function as PropType<MouseEventHandler>,
|
||||||
'onUpdate:openKeys': Function as PropType<(keys: Key[]) => void>,
|
'onUpdate:openKeys': Function as PropType<(keys: Key[]) => void>,
|
||||||
'onUpdate:selectedKeys': Function as PropType<(keys: Key[]) => void>,
|
'onUpdate:selectedKeys': Function as PropType<(keys: Key[]) => void>,
|
||||||
'onUpdate:activeKey': Function as PropType<(key: Key) => void>,
|
'onUpdate:activeKey': Function as PropType<(key: Key) => void>,
|
||||||
|
@ -422,6 +423,7 @@ export default defineComponent({
|
||||||
<>
|
<>
|
||||||
<Overflow
|
<Overflow
|
||||||
{...attrs}
|
{...attrs}
|
||||||
|
onMousedown={props.onMousedown}
|
||||||
prefixCls={`${prefixCls.value}-overflow`}
|
prefixCls={`${prefixCls.value}-overflow`}
|
||||||
component="ul"
|
component="ul"
|
||||||
itemComponent={MenuItem}
|
itemComponent={MenuItem}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Menu, { Item as MenuItem } from '../../menu';
|
import Menu, { Item as MenuItem } from '../../menu';
|
||||||
import type { PropType } from 'vue';
|
import type { PropType } from 'vue';
|
||||||
import { defineComponent, inject, ref } from 'vue';
|
import { onBeforeUnmount, defineComponent, inject, ref } from 'vue';
|
||||||
import type { OptionProps } from './Option';
|
import type { OptionProps } from './Option';
|
||||||
import MentionsContextKey from './MentionsContext';
|
import MentionsContextKey from './MentionsContext';
|
||||||
import Spin from '../../spin';
|
import Spin from '../../spin';
|
||||||
|
@ -22,12 +22,21 @@ export default defineComponent({
|
||||||
setActiveIndex,
|
setActiveIndex,
|
||||||
selectOption,
|
selectOption,
|
||||||
onFocus = noop,
|
onFocus = noop,
|
||||||
onBlur = noop,
|
|
||||||
loading,
|
loading,
|
||||||
} = inject(MentionsContextKey, {
|
} = inject(MentionsContextKey, {
|
||||||
activeIndex: ref(),
|
activeIndex: ref(),
|
||||||
loading: ref(false),
|
loading: ref(false),
|
||||||
});
|
});
|
||||||
|
let timeoutId: any;
|
||||||
|
const onMousedown = (e: MouseEvent) => {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
timeoutId = setTimeout(() => {
|
||||||
|
onFocus(e);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
onBeforeUnmount(() => {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
|
});
|
||||||
return () => {
|
return () => {
|
||||||
const { prefixCls, options } = props;
|
const { prefixCls, options } = props;
|
||||||
const activeOption = options[activeIndex.value] || {};
|
const activeOption = options[activeIndex.value] || {};
|
||||||
|
@ -40,8 +49,7 @@ export default defineComponent({
|
||||||
const option = options.find(({ value }) => value === key);
|
const option = options.find(({ value }) => value === key);
|
||||||
selectOption(option);
|
selectOption(option);
|
||||||
}}
|
}}
|
||||||
onBlur={onBlur}
|
onMousedown={onMousedown}
|
||||||
onFocus={onFocus}
|
|
||||||
>
|
>
|
||||||
{!loading.value &&
|
{!loading.value &&
|
||||||
options.map((option, index) => {
|
options.map((option, index) => {
|
||||||
|
|
|
@ -92,9 +92,8 @@ export default defineComponent({
|
||||||
popupTransitionName={transitionName}
|
popupTransitionName={transitionName}
|
||||||
builtinPlacements={BUILT_IN_PLACEMENTS}
|
builtinPlacements={BUILT_IN_PLACEMENTS}
|
||||||
getPopupContainer={getPopupContainer}
|
getPopupContainer={getPopupContainer}
|
||||||
>
|
v-slots={{ default: slots.default }}
|
||||||
{slots.default?.()}
|
></Trigger>
|
||||||
</Trigger>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
@ -2,6 +2,7 @@ import type { CSSProperties, HTMLAttributes, PropType } from 'vue';
|
||||||
import { computed, defineComponent, ref, watch } from 'vue';
|
import { computed, defineComponent, ref, watch } from 'vue';
|
||||||
import ResizeObserver from '../vc-resize-observer';
|
import ResizeObserver from '../vc-resize-observer';
|
||||||
import classNames from '../_util/classNames';
|
import classNames from '../_util/classNames';
|
||||||
|
import type { MouseEventHandler } from '../_util/EventInterface';
|
||||||
import type { Key, VueNode } from '../_util/type';
|
import type { Key, VueNode } from '../_util/type';
|
||||||
import PropTypes from '../_util/vue-types';
|
import PropTypes from '../_util/vue-types';
|
||||||
import { OverflowContextProvider } from './context';
|
import { OverflowContextProvider } from './context';
|
||||||
|
@ -37,6 +38,8 @@ export interface OverflowProps<ItemType> extends HTMLAttributes {
|
||||||
|
|
||||||
/** When set to `full`, ssr will render full items by default and remove at client side */
|
/** When set to `full`, ssr will render full items by default and remove at client side */
|
||||||
ssr?: 'full';
|
ssr?: 'full';
|
||||||
|
|
||||||
|
onMousedown?: MouseEventHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Overflow = defineComponent({
|
const Overflow = defineComponent({
|
||||||
|
@ -63,6 +66,7 @@ const Overflow = defineComponent({
|
||||||
onVisibleChange: Function as PropType<(visibleCount: number) => void>,
|
onVisibleChange: Function as PropType<(visibleCount: number) => void>,
|
||||||
/** When set to `full`, ssr will render full items by default and remove at client side */
|
/** When set to `full`, ssr will render full items by default and remove at client side */
|
||||||
ssr: String as PropType<'full'>,
|
ssr: String as PropType<'full'>,
|
||||||
|
onMousedown: Function as PropType<MouseEventHandler>,
|
||||||
},
|
},
|
||||||
emits: ['visibleChange'],
|
emits: ['visibleChange'],
|
||||||
setup(props, { attrs, emit }) {
|
setup(props, { attrs, emit }) {
|
||||||
|
@ -247,6 +251,7 @@ const Overflow = defineComponent({
|
||||||
suffix,
|
suffix,
|
||||||
component: Component = 'div' as any,
|
component: Component = 'div' as any,
|
||||||
id,
|
id,
|
||||||
|
onMousedown,
|
||||||
} = props;
|
} = props;
|
||||||
const { class: className, style, ...restAttrs } = attrs;
|
const { class: className, style, ...restAttrs } = attrs;
|
||||||
let suffixStyle: CSSProperties = {};
|
let suffixStyle: CSSProperties = {};
|
||||||
|
@ -346,6 +351,7 @@ const Overflow = defineComponent({
|
||||||
id={id}
|
id={id}
|
||||||
class={classNames(!invalidate.value && prefixCls, className)}
|
class={classNames(!invalidate.value && prefixCls, className)}
|
||||||
style={style}
|
style={style}
|
||||||
|
onMousedown={onMousedown}
|
||||||
{...restAttrs}
|
{...restAttrs}
|
||||||
>
|
>
|
||||||
{mergedData.value.map(internalRenderItemNode)}
|
{mergedData.value.map(internalRenderItemNode)}
|
||||||
|
|
Loading…
Reference in New Issue