Skip to content

Commit 92795a8

Browse files
authored
refactor: mentions (#6255)
* refactor: mentions * refactor: mentions menu provider
1 parent 44e5d09 commit 92795a8

File tree

11 files changed

+263
-218
lines changed

11 files changed

+263
-218
lines changed

components/mentions/index.tsx

+24-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import { optionProps } from '../vc-mentions/src/Option';
1212
import type { KeyboardEventHandler } from '../_util/EventInterface';
1313
import type { InputStatus } from '../_util/statusUtils';
1414
import { getStatusClassNames, getMergedStatus } from '../_util/statusUtils';
15+
import useStyle from './style';
16+
import { useProvideOverride } from '../menu/src/OverrideContext';
17+
import warning from '../_util/warning';
1518

1619
interface MentionsConfig {
1720
prefix?: string | string[];
@@ -98,12 +101,27 @@ const Mentions = defineComponent({
98101
slots: ['notFoundContent', 'option'],
99102
setup(props, { slots, emit, attrs, expose }) {
100103
const { prefixCls, renderEmpty, direction } = useConfigInject('mentions', props);
104+
const [wrapSSR, hashId] = useStyle(prefixCls);
101105
const focused = ref(false);
102106
const vcMentions = ref(null);
103107
const value = ref(props.value ?? props.defaultValue ?? '');
104108
const formItemContext = useInjectFormItemContext();
105109
const formItemInputContext = FormItemInputContext.useInject();
106110
const mergedStatus = computed(() => getMergedStatus(formItemInputContext.status, props.status));
111+
useProvideOverride({
112+
prefixCls: computed(() => `${prefixCls.value}-menu`),
113+
mode: computed(() => 'vertical'),
114+
selectable: computed(() => false),
115+
onClick: () => {},
116+
validator: ({ mode }) => {
117+
// Warning if use other mode
118+
warning(
119+
!mode || mode === 'vertical',
120+
'Mentions',
121+
`mode="${mode}" is not supported for Mentions's Menu.`,
122+
);
123+
},
124+
});
107125
watch(
108126
() => props.value,
109127
val => {
@@ -182,6 +200,7 @@ const Mentions = defineComponent({
182200
},
183201
getStatusClassNames(prefixCls.value, mergedStatus.value),
184202
!hasFeedback && className,
203+
hashId.value,
185204
);
186205

187206
const mentionsProps = {
@@ -206,11 +225,12 @@ const Mentions = defineComponent({
206225
const mentions = (
207226
<VcMentions
208227
{...mentionsProps}
228+
dropdownClassName={hashId.value}
209229
v-slots={{ notFoundContent: getNotFoundContent, option: slots.option }}
210230
></VcMentions>
211231
);
212232
if (hasFeedback) {
213-
return (
233+
return wrapSSR(
214234
<div
215235
class={classNames(
216236
`${prefixCls.value}-affix-wrapper`,
@@ -220,14 +240,15 @@ const Mentions = defineComponent({
220240
hasFeedback,
221241
),
222242
className,
243+
hashId.value,
223244
)}
224245
>
225246
{mentions}
226247
<span class={`${prefixCls.value}-suffix`}>{feedbackIcon}</span>
227-
</div>
248+
</div>,
228249
);
229250
}
230-
return mentions;
251+
return wrapSSR(mentions);
231252
};
232253
},
233254
});

components/mentions/style/index.less

-179
This file was deleted.

0 commit comments

Comments
 (0)