diff --git a/components/tag/index.tsx b/components/tag/index.tsx index be61ee7fa..bebe40270 100644 --- a/components/tag/index.tsx +++ b/components/tag/index.tsx @@ -7,6 +7,7 @@ import Wave from '../_util/wave'; import type { PresetColorType, PresetStatusColorType } from '../_util/colors'; import { isPresetColor, isPresetStatusColor } from '../_util/colors'; import type { LiteralUnion } from '../_util/type'; +import { eventType } from '../_util/type'; import CheckableTag from './CheckableTag'; import useConfigInject from '../config-provider/hooks/useConfigInject'; import warning from '../_util/warning'; @@ -25,9 +26,7 @@ export const tagProps = () => ({ onClose: { type: Function as PropType<(e: MouseEvent) => void>, }, - onClick: { - type: Function as PropType<(e: MouseEvent) => void>, - }, + onClick: eventType<(e: MouseEvent) => void>(), 'onUpdate:visible': Function as PropType<(vis: boolean) => void>, icon: PropTypes.any, }); @@ -41,7 +40,7 @@ const Tag = defineComponent({ props: tagProps(), // emits: ['update:visible', 'close'], slots: ['closeIcon', 'icon'], - setup(props: TagProps, { slots, emit, attrs }) { + setup(props, { slots, emit, attrs }) { const { prefixCls, direction } = useConfigInject('tag', props); const [wrapSSR, hashId] = useStyle(prefixCls); @@ -89,14 +88,16 @@ const Tag = defineComponent({ ); const tagClassName = computed(() => - classNames(prefixCls.value, hashId.value, attrs.class, { + classNames(prefixCls.value, hashId.value, { [`${prefixCls.value}-${props.color}`]: isInternalColor.value, [`${prefixCls.value}-has-color`]: props.color && !isInternalColor.value, [`${prefixCls.value}-hidden`]: !visible.value, [`${prefixCls.value}-rtl`]: direction.value === 'rtl', }), ); - + const handleClick = (e: MouseEvent) => { + emit('click', e); + }; return () => { const { icon = slots.icon?.(), @@ -133,12 +134,12 @@ const Tag = defineComponent({ children ); - const isNeedWave = 'onClick' in attrs; - + const isNeedWave = props.onClick !== undefined; const tagNode = ( {kids}