Skip to content

Commit

Permalink
fix(rate): #2550 鼠标快速移动,会出现多个text显示的问题 (#2551)
Browse files Browse the repository at this point in the history
* fix: [Rate] 鼠标快速移动,会出现多个text显示的问题

* fix(rate): 修复rate组件鼠标快速移动,会出现多个text显示的问题

fix #2550

* fix: 修改传参数写法

fix #2550
  • Loading branch information
Jon-Millent authored Oct 19, 2023
1 parent db201ca commit a399964
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions src/rate/Rate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,20 @@ import { rateDefaultProps } from './defaultProps';

export interface RateProps extends TdRateProps, StyledProps {}

// 评分图标
// fix: 2550
const RateIcon = ({ icon, ...props }) => {
const { StarFilledIcon } = useGlobalIcon({ StarFilledIcon: TdStarFilledIcon });
if (React.isValidElement(icon)) {
return React.cloneElement(icon, props);
}
return <StarFilledIcon {...props} />;
};

const Rate = forwardRef((props: RateProps, ref: React.Ref<HTMLDivElement>) => {
const { allowHalf, color, count, disabled, gap, showText, size, texts, icon, className, style, onChange } = props;

const { classPrefix } = useConfig();
const { StarFilledIcon } = useGlobalIcon({ StarFilledIcon: TdStarFilledIcon });
const [starValue = 0, setStarValue] = useControlled(props, 'value', onChange);

const [hoverValue = undefined, setHoverValue] = useState<number | undefined>(undefined);
Expand All @@ -25,14 +34,6 @@ const Rate = forwardRef((props: RateProps, ref: React.Ref<HTMLDivElement>) => {
const activeColor = Array.isArray(color) ? color[0] : color;
const defaultColor = Array.isArray(color) ? color[1] : 'var(--td-bg-color-component)';

// 评分图标
const RateIcon = (props: any) => {
if (React.isValidElement(icon)) {
return React.cloneElement(icon, props);
}
return <StarFilledIcon {...props} />;
};

const getStarValue = (event: MouseEvent<HTMLElement>, index: number) => {
if (allowHalf) {
const rootNode = rootRef.current;
Expand Down Expand Up @@ -87,19 +88,19 @@ const Rate = forwardRef((props: RateProps, ref: React.Ref<HTMLDivElement>) => {
{showText ? (
<TooltipLite key={index} content={texts[displayValue - 1]}>
<div className={`${classPrefix}-rate__star-top`}>
<RateIcon size={size} color={activeColor} />
<RateIcon size={size} color={activeColor} icon={icon} />
</div>
<div className={`${classPrefix}-rate__star-bottom`}>
<RateIcon size={size} color={defaultColor} />
<RateIcon size={size} color={defaultColor} icon={icon} />
</div>
</TooltipLite>
) : (
<>
<div className={`${classPrefix}-rate__star-top`}>
<RateIcon size={size} color={activeColor} />
<RateIcon size={size} color={activeColor} icon={icon} />
</div>
<div className={`${classPrefix}-rate__star-bottom`}>
<RateIcon size={size} color={defaultColor} />
<RateIcon size={size} color={defaultColor} icon={icon} />
</div>
</>
)}
Expand Down

0 comments on commit a399964

Please sign in to comment.