DEV Community

Doan Trong Nam
Doan Trong Nam

Posted on • Edited on

How to Create a Duration-Based Progress Bar with PrimeVue ProgressBar

I used to struggle with creating a progress bar using PrimeVue's ProgressBar component that smoothly runs from 0% to 100% over a specified duration. However, after reading the PrimeVue documentation, I couldn't find any built-in option to achieve this. So, a bit of trickery is needed here.

First, let's check out the documentation for this component: PrimeVue ProgressBar
We can see that we need to pass a prop called :value, which is a number between 0 and 100 representing the progress percentage.

Next, let's take a look at the Dynamnic
section of the documentation.

Here, we can see that whenever the value of the progress bar changes, it takes some time for the old value to transition to the new one. So, how long does this transition take?

Let's inspect this element:

Inspect ProgressBar's css

Notice that there is a CSS property transition: width 1s ease-in-out;. This means it takes 1 second for the progress bar to update its value. In other words, when changing the value from 0% to 100%, it takes 1 second to complete. So, the default duration for this component is 1 second.

To customize this duration, we simply need to modify the transition-duration property of the progress-bar-value element inside the ProgressBar component. We can achieve this using PrimeVue's passthrough feature:

<template>
  <ProgressBar :value="value" :pt:value:style="{ 'transition-duration': '3s' }" />
</template>
Enter fullscreen mode Exit fullscreen mode

Now, simply update the value to see the effect.

Final Result:

// ~/components/app/progress-bar.vue
<template>
  <p-progress-bar
    v-bind="props"
    :pt:value:style="{ 'transition-duration': props.duration }"
  />
</template>

<script setup lang="ts">
import type { ProgressBarProps } from 'primevue';

// define prop type to get suggestion in VSCode
interface AppProgressBarProps extends /* @vue-ignore */ ProgressBarProps {
  duration?: string;
}

const props = withDefaults(defineProps<AppProgressBarProps>(), {
  duration: '3s',
});
</script>
Enter fullscreen mode Exit fullscreen mode

StackBlitz: https://stackblitz.com/edit/nuxt-starter-cdnmfmvv?file=components%2Fapp%2Fprogress-bar.vue

Dynatrace image

Observability should elevate – not hinder – the developer experience.

Is your troubleshooting toolset diminishing code output? With Dynatrace, developers stay in flow while debugging – reducing downtime and getting back to building faster.

Explore Observability for Developers

Top comments (1)

Collapse
 
_mymy_67 profile image
ドアンニャー チュック ミー

Dear Mr.Nam, I want to connect with you to exchange about a opportunity for you, can you accept me on LinkedIn? Here is my LinkedIn link, please check it soon.
linkedin.com/in/yumie-59b739337

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

👋 Kindness is contagious

Dive into this thoughtful piece, beloved in the supportive DEV Community. Coders of every background are invited to share and elevate our collective know-how.

A sincere "thank you" can brighten someone's day—leave your appreciation below!

On DEV, sharing knowledge smooths our journey and tightens our community bonds. Enjoyed this? A quick thank you to the author is hugely appreciated.

Okay