Skip to content

Commit

Permalink
feat(tag): checkTag组件children使用parseTNode渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
raylotan committed Aug 11, 2024
1 parent 526f4a7 commit e0d2a5c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/tag/CheckTag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import React, {
memo
} from 'react';
import { Icon } from 'tdesign-icons-react';
import parseTNode from 'tdesign-mobile-react/_util/parseTNode';
import { StyledProps } from 'tdesign-mobile-react/common';
import useConfig from '../_util/useConfig';
import useDefault from '../_util/useDefault';
Expand All @@ -13,7 +14,6 @@ import { TdCheckTagProps } from './type';

export interface TagCheckProps extends TdCheckTagProps, StyledProps { }


const TagCheck = memo(
forwardRef<HTMLSpanElement, TagCheckProps>((originProps, ref) => {
const props = useDefaultProps(originProps, checkTagDefaultProps)
Expand Down Expand Up @@ -65,6 +65,8 @@ const TagCheck = memo(
return content;
}

const childNode = parseTNode(renderText()) || parseTNode(children)

const tagStyle = {
...style,
};
Expand All @@ -76,7 +78,6 @@ const TagCheck = memo(
}
};


const handleClose = (e) => {
e.stopPropagation();
if (!props.disabled) {
Expand All @@ -88,14 +89,14 @@ const TagCheck = memo(
<span
ref={ref}
className={checkTagClass}
aria-disabled={props.disabled}
aria-disabled={disabled}
role="button"
onClick={handleClick}
style={tagStyle}
{...otherProps}
>
{icon && <span className={`${baseClass}__icon`}>{icon}</span>}
<span className={`${baseClass}__text`}>{renderText() || children}</span>
<span className={`${baseClass}__text`}>{childNode}</span>
{props.closable && (
<span className={`${baseClass}__icon-close`} onClick={handleClose}>
<Icon name="close" />
Expand Down

0 comments on commit e0d2a5c

Please sign in to comment.