fix(Progress): prevent NaN percent display when indeterminate

This commit is contained in:
Benjamin Canac
2024-02-15 11:48:49 +01:00
parent c488b28c3c
commit a55a08a91e

View File

@@ -9,7 +9,7 @@
</slot> </slot>
<progress :class="progressClass" v-bind="{ value, max: realMax }"> <progress :class="progressClass" v-bind="{ value, max: realMax }">
{{ Math.round(percent) }}% {{ percent !== undefined ? `${Math.round(percent)}%` : undefined }}
</progress> </progress>
<div v-if="isSteps" :class="stepsClass"> <div v-if="isSteps" :class="stepsClass">
@@ -157,7 +157,7 @@ export default defineComponent({
return index === 0 return index === 0
} }
function stepClasses (index: string|number) { function stepClasses (index: string | number) {
index = Number(index) index = Number(index)
const classes = [stepClass.value] const classes = [stepClass.value]
@@ -189,6 +189,10 @@ export default defineComponent({
}) })
const percent = computed(() => { const percent = computed(() => {
if (isIndeterminate.value) {
return undefined
}
switch (true) { switch (true) {
case props.value < 0: return 0 case props.value < 0: return 0
case props.value > (realMax.value as number): return 100 case props.value > (realMax.value as number): return 100
@@ -237,9 +241,11 @@ progress:indeterminate {
&:after { &:after {
animation: carousel 2s ease-in-out infinite; animation: carousel 2s ease-in-out infinite;
} }
&::-webkit-progress-value { &::-webkit-progress-value {
animation: carousel 2s ease-in-out infinite; animation: carousel 2s ease-in-out infinite;
} }
&::-moz-progress-bar { &::-moz-progress-bar {
animation: carousel 2s ease-in-out infinite; animation: carousel 2s ease-in-out infinite;
} }
@@ -249,9 +255,11 @@ progress:indeterminate {
&:after { &:after {
animation: carousel-inverse 2s ease-in-out infinite; animation: carousel-inverse 2s ease-in-out infinite;
} }
&::-webkit-progress-value { &::-webkit-progress-value {
animation: carousel-inverse 2s ease-in-out infinite; animation: carousel-inverse 2s ease-in-out infinite;
} }
&::-moz-progress-bar { &::-moz-progress-bar {
animation: carousel-inverse 2s ease-in-out infinite; animation: carousel-inverse 2s ease-in-out infinite;
} }
@@ -261,9 +269,11 @@ progress:indeterminate {
&:after { &:after {
animation: swing 3s ease-in-out infinite; animation: swing 3s ease-in-out infinite;
} }
&::-webkit-progress-value { &::-webkit-progress-value {
animation: swing 3s ease-in-out infinite; animation: swing 3s ease-in-out infinite;
} }
&::-moz-progress-bar { &::-moz-progress-bar {
animation: swing 3s ease-in-out infinite; animation: swing 3s ease-in-out infinite;
} }
@@ -273,9 +283,11 @@ progress:indeterminate {
&::after { &::after {
animation: elastic 3s ease-in-out infinite; animation: elastic 3s ease-in-out infinite;
} }
&::-webkit-progress-value { &::-webkit-progress-value {
animation: elastic 3s ease-in-out infinite; animation: elastic 3s ease-in-out infinite;
} }
&::-moz-progress-bar { &::-moz-progress-bar {
animation: elastic 3s ease-in-out infinite; animation: elastic 3s ease-in-out infinite;
} }
@@ -283,26 +295,65 @@ progress:indeterminate {
} }
@keyframes carousel { @keyframes carousel {
0%, 100% { width: 50% }
0% { transform: translateX(-100%) } 0%,
100% { transform: translateX(200%) } 100% {
width: 50%
}
0% {
transform: translateX(-100%)
}
100% {
transform: translateX(200%)
}
} }
@keyframes carousel-inverse { @keyframes carousel-inverse {
0%, 100% { width: 50% }
0% { transform: translateX(200%) } 0%,
100% { transform: translateX(-100%) } 100% {
width: 50%
}
0% {
transform: translateX(200%)
}
100% {
transform: translateX(-100%)
}
} }
@keyframes swing { @keyframes swing {
0%, 100% { width: 50% }
0%, 100% { transform: translateX(-25%) } 0%,
50% { transform: translateX(125%) } 100% {
width: 50%
}
0%,
100% {
transform: translateX(-25%)
}
50% {
transform: translateX(125%)
}
} }
@keyframes elastic { @keyframes elastic {
/* Firefox doesn't do "margin: 0 auto", we have to play with margin-left */ /* Firefox doesn't do "margin: 0 auto", we have to play with margin-left */
0%, 100% { width: 50%; margin-left: 25%; } 0%,
50% { width: 90%; margin-left: 5% } 100% {
} width: 50%;
</style> margin-left: 25%;
}
50% {
width: 90%;
margin-left: 5%
}
}</style>