Skip to content

Commit

Permalink
fix: mentions cannot select, close #5233
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Feb 25, 2022
1 parent c7492a0 commit f0bc380
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 3 additions & 1 deletion components/menu/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -64,6 +64,7 @@ export const menuProps = {
onClick: [Function, Array] as PropType<MenuClickEventHandler>,
onFocus: Function as PropType<FocusEventHandler>,
onBlur: Function as PropType<FocusEventHandler>,
onMousedown: Function as PropType<MouseEventHandler>,
'onUpdate:openKeys': Function as PropType<(keys: Key[]) => void>,
'onUpdate:selectedKeys': Function as PropType<(keys: Key[]) => void>,
'onUpdate:activeKey': Function as PropType<(key: Key) => void>,
Expand Down Expand Up @@ -422,6 +423,7 @@ export default defineComponent({
<>
<Overflow
{...attrs}
onMousedown={props.onMousedown}
prefixCls={`${prefixCls.value}-overflow`}
component="ul"
itemComponent={MenuItem}
Expand Down
16 changes: 12 additions & 4 deletions components/vc-mentions/src/DropdownMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Menu, { Item as MenuItem } from '../../menu';
import type { PropType } from 'vue';
import { defineComponent, inject, ref } from 'vue';
import { onBeforeUnmount, defineComponent, inject, ref } from 'vue';
import type { OptionProps } from './Option';
import MentionsContextKey from './MentionsContext';
import Spin from '../../spin';
Expand All @@ -22,12 +22,21 @@ export default defineComponent({
setActiveIndex,
selectOption,
onFocus = noop,
onBlur = noop,
loading,
} = inject(MentionsContextKey, {
activeIndex: ref(),
loading: ref(false),
});
let timeoutId: any;
const onMousedown = (e: MouseEvent) => {
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
onFocus(e);
});
};
onBeforeUnmount(() => {
clearTimeout(timeoutId);
});
return () => {
const { prefixCls, options } = props;
const activeOption = options[activeIndex.value] || {};
Expand All @@ -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) => {
Expand Down
5 changes: 2 additions & 3 deletions components/vc-mentions/src/KeywordTrigger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ export default defineComponent({
popupTransitionName={transitionName}
builtinPlacements={BUILT_IN_PLACEMENTS}
getPopupContainer={getPopupContainer}
>
{slots.default?.()}
</Trigger>
v-slots={{ default: slots.default }}
></Trigger>
);
};
},
Expand Down
6 changes: 6 additions & 0 deletions components/vc-overflow/Overflow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 */
ssr?: 'full';

onMousedown?: MouseEventHandler;
}

const Overflow = defineComponent({
Expand All @@ -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<MouseEventHandler>,
},
emits: ['visibleChange'],
setup(props, { attrs, emit }) {
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -346,6 +351,7 @@ const Overflow = defineComponent({
id={id}
class={classNames(!invalidate.value && prefixCls, className)}
style={style}
onMousedown={onMousedown}
{...restAttrs}
>
{mergedData.value.map(internalRenderItemNode)}
Expand Down

0 comments on commit f0bc380

Please sign in to comment.