温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.muo.com/react-progress-bar-accessible-create/
点击访问原文链接

How to Create an Accessible Progress Bar With React

How to Create an Accessible Progress Bar With React Menu Sign in now Close PC & Mobile Submenu Windows2 Linux Android Apple Technical Submenu Tech Explained Security Software Submenu Productivity Internet Creative Screen Submenu Entertainment Streaming Home Submenu Smart Home Home News Sign in Newsletter Menu Follow Followed Like More Action Sign in now Productivity Android Smart TVs Networking Windows 11 Entertainment Close
How to Create an Accessible Progress Bar With React Image from Pexels. No attribution is required. By  Mary Gathoni Published Oct 7, 2022, 7:00 AM EDT Mary writes for the programming section and has been doing so for the past two years. Her educational background is in Computer Science and Physics. Sign in to your MakeUseOf account

Progress bars are great for user engagement because they provide a goal to achieve. Instead of staring at a web page waiting on a resource, you see a progress bar filling up. Progress bars should not be limited to sighted users only. Everyone should be able to understand your progress bar with ease.

So how do you build an accessible progress bar with React?

Create a Progress Bar Component

Create a new component called ProgressBar.js and add the following code:

const ProgressBar = ({progress}) => {
return (


{`${progress}%`}


);
};

export default ProgressBar;

The first div element is the container and the second div is the actual progress bar. The span element holds the progress bar percentage.

For accessibility purposes, the second div has the following attributes:

A role of progressbar. aria-valuenow to indicate the current value of the progress bar. aria-valuemin to indicate the minimum value of the progress bar. aria-valuemax to indicate the maximum value of the progress bar.

The aria-valuemin and aria-valuemax attributes are not necessary if the progress bar maximum and minimum values are 0 and 100 since HTML defaults to these values.

Styling the Progress Bar

You can style the progress bar using inline styles or a CSS-in-JS library like styled-components. Both of these approaches provide a simple way of passing props from the component to the CSS.

You need this functionality because the width of the progress bar depends on the progress value passed in as props.

You can use these inline styles:

const container = {
height: 20,
width: "100%",
backgroundColor: "#fff",
borderRadius: 50,
margin: 50
}

const bar = {
height: "100%",
width: `${progress}%`,
backgroundColor: "#90CAF9",
borderRadius: "inherit",
}

const label = {
padding: "1rem",
color: "#000000",
}

Modify the return portion of the component to include styles as shown below:


{`${progress}%`}


Render the progress bar like this:


This displays a progress bar with 50 percent complete.

Building Components in React

You can now create an accessible progress bar with percentages that you can reuse in any part of your application. With React, you can create independent UI components like these and use them as building blocks of a complex application.

Close
Recommended An Intro to Web Components and Component-Based Architecture 4 smart home devices that work much better on Zigbee or Thread than Wi-Fi I tried to do everything on the TCL NXTPAPER 14, and it turns out it's really just for readers This Linux command is the only backup tool I'll ever need Join Our Team Our Audience About Us Press & Events Media Coverage Contact Us Follow Us Advertising Careers Terms Privacy Policies MakeUseOf is part of the Valnet Publishing Group Copyright © 2026 Valnet Inc.

How to Create an Accessible Progress Bar With React,AI智能索引,全网链接索引,智能导航,网页索引

    Make sure your web app