fix(Progress): width overflow (#13519)

This commit is contained in:
pany
2025-06-22 19:41:45 +08:00
committed by GitHub
parent 24eb78dbaf
commit da72797328
2 changed files with 9 additions and 7 deletions
+7 -3
View File
@@ -37,15 +37,18 @@ export default defineComponent({
props.inactive ? undefined : props.color, props.inactive ? undefined : props.color,
); );
const format = (rate: Numeric) => Math.min(Math.max(+rate, 0), 100);
const renderPivot = () => { const renderPivot = () => {
const { textColor, pivotText, pivotColor, percentage } = props; const { textColor, pivotText, pivotColor, percentage } = props;
const safePercentage = format(percentage);
const text = pivotText ?? `${percentage}%`; const text = pivotText ?? `${percentage}%`;
if (props.showPivot && text) { if (props.showPivot && text) {
const style = { const style = {
color: textColor, color: textColor,
left: `${+percentage}%`, left: `${safePercentage}%`,
transform: `translate(-${+percentage}%,-50%)`, transform: `translate(-${safePercentage}%,-50%)`,
background: pivotColor || background.value, background: pivotColor || background.value,
}; };
@@ -62,12 +65,13 @@ export default defineComponent({
return () => { return () => {
const { trackColor, percentage, strokeWidth } = props; const { trackColor, percentage, strokeWidth } = props;
const safePercentage = format(percentage);
const rootStyle = { const rootStyle = {
background: trackColor, background: trackColor,
height: addUnit(strokeWidth), height: addUnit(strokeWidth),
}; };
const portionStyle = { const portionStyle = {
width: `${percentage}%`, width: `${safePercentage}%`,
background: background.value, background: background.value,
}; };
+2 -4
View File
@@ -21,14 +21,12 @@ const t = useTranslate({
const percentage = ref(50); const percentage = ref(50);
const format = (rate: number) => Math.min(Math.max(rate, 0), 100);
const add = () => { const add = () => {
percentage.value = format(percentage.value + 20); percentage.value = percentage.value + 20;
}; };
const reduce = () => { const reduce = () => {
percentage.value = format(percentage.value - 20); percentage.value = percentage.value - 20;
}; };
</script> </script>