1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-06 00:49:58 +00:00

fix: avoid bar width division by zero (#1826)

This commit is contained in:
Zaidhaan 2023-03-01 05:44:15 +08:00 committed by GitHub
parent a5cece7b42
commit 2842a5f383
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -57,7 +57,7 @@ const votersCount = $computed(() => poll.votersCount ?? poll.votesCount ?? 0)
<div
v-for="(option, index) of poll.options"
:key="index" py-1 relative
:style="{ '--bar-width': toPercentage((option.votesCount || 0) / votersCount) }"
:style="{ '--bar-width': toPercentage(votersCount === 0 ? 0 : (option.votesCount ?? 0) / votersCount) }"
>
<div flex justify-between pb-2 w-full>
<span inline-flex align-items>
@ -67,7 +67,7 @@ const votersCount = $computed(() => poll.votersCount ?? poll.votesCount ?? 0)
<span text-primary-active> {{ formatPercentage(votersCount > 0 ? (option.votesCount || 0) / votersCount : 0) }}</span>
</div>
<div class="bg-gray/40" rounded-l-sm rounded-r-lg h-5px w-full>
<div bg-primary-active h-full class="w-[var(--bar-width)]" />
<div bg-primary-active h-full min-w="1%" class="w-[var(--bar-width)]" />
</div>
</div>
</template>