Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(rate): #2550 鼠标快速移动,会出现多个text显示的问题 #2551

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading