diff --git a/packages/components/mention/src/mention-dropdown.ts b/packages/components/mention/src/mention-dropdown.ts index 3dcaa8ec22..d1875ac02b 100644 --- a/packages/components/mention/src/mention-dropdown.ts +++ b/packages/components/mention/src/mention-dropdown.ts @@ -2,6 +2,17 @@ import { buildProps, definePropType, isString } from '@element-plus/utils' import type { MentionOption } from './types' +export interface MentionDropdownProps { + options?: MentionOption[] + loading?: boolean + disabled?: boolean + contentId?: string + ariaLabel?: string +} + +/** + * @deprecated Removed after 3.0.0, Use `MentionDropdownProps` instead. + */ export const mentionDropdownProps = buildProps({ options: { type: definePropType(Array), diff --git a/packages/components/mention/src/mention-dropdown.vue b/packages/components/mention/src/mention-dropdown.vue index 6bf2402b58..55846fe2ad 100644 --- a/packages/components/mention/src/mention-dropdown.vue +++ b/packages/components/mention/src/mention-dropdown.vue @@ -45,15 +45,18 @@ import { computed, nextTick, ref, watch } from 'vue' import { useLocale, useNamespace } from '@element-plus/hooks' import { scrollIntoView } from '@element-plus/utils' import ElScrollbar from '@element-plus/components/scrollbar' -import { mentionDropdownEmits, mentionDropdownProps } from './mention-dropdown' +import { mentionDropdownEmits } from './mention-dropdown' +import type { MentionDropdownProps } from './mention-dropdown' import type { MentionOption } from './types' defineOptions({ name: 'ElMentionDropdown', }) -const props = defineProps(mentionDropdownProps) +const props = withDefaults(defineProps(), { + options: () => [], +}) const emit = defineEmits(mentionDropdownEmits) const ns = useNamespace('mention') diff --git a/packages/components/mention/src/mention.ts b/packages/components/mention/src/mention.ts index 93f584043f..12633ff707 100644 --- a/packages/components/mention/src/mention.ts +++ b/packages/components/mention/src/mention.ts @@ -10,11 +10,79 @@ import { inputProps } from '@element-plus/components/input' import { filterOption } from './helper' import { useTooltipContentProps } from '@element-plus/components/tooltip' -import type { ExtractPropTypes, ExtractPublicPropTypes } from 'vue' +import type { ExtractPublicPropTypes } from 'vue' import type Mention from './mention.vue' import type { MentionOption } from './types' import type { Options } from '@element-plus/components/popper' +import type { InputProps } from '@element-plus/components/input' +import type { ElTooltipContentProps } from '@element-plus/components/tooltip' +export interface MentionProps extends InputProps { + /** + * @description mention options list + */ + options?: MentionOption[] + /** + * @description prefix character to trigger mentions. The string length must be exactly 1. + */ + prefix?: string | string[] + /** + * @description character to split mentions. The string length must be exactly 1. + */ + split?: string + /** + * @description customize filter option logic. + */ + filterOption?: false | typeof filterOption + /** + * @description set popup placement + */ + placement?: 'bottom' | 'top' + /** + * @description whether the dropdown panel has an arrow + */ + showArrow?: boolean + /** + * @description offset of the dropdown panel + */ + offset?: number + /** + * @description when backspace is pressed to delete, whether the mention content is deleted as a whole + */ + whole?: boolean + /** + * @description when backspace is pressed to delete, check if the mention is a whole + */ + checkIsWhole?: (pattern: string, prefix: string) => boolean + /** + * @description input value + */ + modelValue?: string + /** + * @description whether the dropdown panel of mentions is in a loading state. + */ + loading?: boolean + /** + * @description custom class name for dropdown panel + */ + popperClass?: ElTooltipContentProps['popperClass'] + /** + * @description custom style for dropdown panel + */ + popperStyle?: ElTooltipContentProps['popperStyle'] + /** + * @description [popper.js](https://popper.js.org/docs/v2/) parameters + */ + popperOptions?: Partial + /** + * @description configuration options + */ + props?: MentionOptionProps +} + +/** + * @deprecated Removed after 3.0.0, Use `MentionProps` instead. + */ export const mentionProps = buildProps({ ...inputProps, /** @@ -130,7 +198,9 @@ export const mentionEmits = { } export type MentionEmits = typeof mentionEmits -export type MentionProps = ExtractPropTypes +/** + * @deprecated Removed after 3.0.0, Use `MentionProps` instead. + */ export type MentionPropsPublic = ExtractPublicPropTypes export type MentionInstance = InstanceType & unknown diff --git a/packages/components/mention/src/mention.vue b/packages/components/mention/src/mention.vue index 72c4c12466..1fc744eec8 100644 --- a/packages/components/mention/src/mention.vue +++ b/packages/components/mention/src/mention.vue @@ -60,7 +60,10 @@ import { computed, mergeProps, nextTick, ref } from 'vue' import { pick } from 'lodash-unified' import { useFocusController, useId, useNamespace } from '@element-plus/hooks' -import ElInput, { inputProps } from '@element-plus/components/input' +import ElInput, { + inputProps, + inputPropsDefaults, +} from '@element-plus/components/input' import ElTooltip from '@element-plus/components/tooltip' import { EVENT_CODE, @@ -69,10 +72,11 @@ import { } from '@element-plus/constants' import { useFormDisabled } from '@element-plus/components/form' import { getEventCode, isFunction } from '@element-plus/utils' -import { mentionDefaultProps, mentionEmits, mentionProps } from './mention' -import { getCursorPosition, getMentionCtx } from './helper' +import { mentionDefaultProps, mentionEmits } from './mention' +import { filterOption, getCursorPosition, getMentionCtx } from './helper' import ElMentionDropdown from './mention-dropdown.vue' +import type { MentionProps } from './mention' import type { Placement } from '@popperjs/core' import type { CSSProperties } from 'vue' import type { InputInstance } from '@element-plus/components/input' @@ -84,7 +88,17 @@ defineOptions({ inheritAttrs: false, }) -const props = defineProps(mentionProps) +const props = withDefaults(defineProps(), { + ...inputPropsDefaults, + options: () => [], + prefix: '@', + split: ' ', + filterOption: () => filterOption, + placement: 'bottom', + offset: 0, + popperOptions: () => ({}), + props: () => mentionDefaultProps, +}) const emit = defineEmits(mentionEmits) const passInputProps = computed(() => pick(props, Object.keys(inputProps)))