Skip to content

Commit 26a3ef1

Browse files
patrickhlaukejulien-deramondmdo
authored
Rework progress bar markup and styles (#36831)
* Rework progress bar markup and styles Logically moves the various `role` and `aria-` attributes to the `.progress` element itself, leaving the `.progress-bar` to be used purely for the visual presentation. This fixes the problem #36736 that in certain browser/AT combinations, zero-value/zero-width progress bars are completely ignored and not announced. For multiple/stacked progress bars, this PR introduces a new wrapper and class `.progress-stacked`, to accommodate for the fact that with the more logical structure above, we need full `.progress` elements with child `.progress-bar` elements, and can't get away with the fudge we had before of having a single `.progress` with multiple `.progress-bar`s. Note that the old markup structures still work with this change, so this could be considered a non-breaking change - though one we definitely want to highlight as it's more accessible (as it now guarantees that zero-value/zero-width progress bars, whether on their own or as part of a multi/stacked bar, are actually announced) * Add a note about progress bar change in migration guide * Add notes with old markup examples and explanation * Fix bundlewatch * Update site/content/docs/5.2/components/progress.md Co-authored-by: Julien Déramond <julien.deramond@orange.com> * Reintroduce deleted styles Turns out they're needed for correct positioning of text inside progress bar * Move changes in markup to Migrationg guide, link to that from top of progress page, rewrite some content * Fix typo in callout * Clarify "Sizing" section * Remove redundant "now" Co-authored-by: Julien Déramond <julien.deramond@orange.com> Co-authored-by: Julien Déramond <juderamond@gmail.com> Co-authored-by: Mark Otto <markdotto@gmail.com> Co-authored-by: Mark Otto <markd.otto@gmail.com>
1 parent 019a977 commit 26a3ef1

File tree

6 files changed

+155
-81
lines changed

6 files changed

+155
-81
lines changed

scss/_progress.scss

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
}
99
// scss-docs-end progress-keyframes
1010

11-
.progress {
11+
.progress,
12+
.progress-stacked {
1213
// scss-docs-start progress-css-vars
1314
--#{$prefix}progress-height: #{$progress-height};
1415
@include rfs($progress-font-size, --#{$prefix}progress-font-size);
@@ -46,6 +47,14 @@
4647
background-size: var(--#{$prefix}progress-height) var(--#{$prefix}progress-height);
4748
}
4849

50+
.progress-stacked > .progress {
51+
overflow: visible;
52+
}
53+
54+
.progress-stacked > .progress > .progress-bar {
55+
width: 100%;
56+
}
57+
4958
@if $enable-transitions {
5059
.progress-bar-animated {
5160
animation: $progress-bar-animation-timing progress-bar-stripes;

site/content/docs/5.2/components/progress.md

+67-52
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,72 @@ group: components
66
toc: true
77
---
88

9+
{{< callout info >}}
10+
**New markup in v5.3.0 —** We've deprecated the previous HTML structure for progress bars and replaced it with a more accessible one. The previous structure will continue to work until v6. [See what's changed in our migration guide.]({{< docsref "/migration#improved-markup-for-progress-bars" >}})
11+
{{< /callout >}}
12+
913
## How it works
1014

1115
Progress components are built with two HTML elements, some CSS to set the width, and a few attributes. We don't use [the HTML5 `<progress>` element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/progress), ensuring you can stack progress bars, animate them, and place text labels over them.
1216

1317
- We use the `.progress` as a wrapper to indicate the max value of the progress bar.
14-
- We use the inner `.progress-bar` to indicate the progress so far.
15-
- The `.progress-bar` requires an inline style, utility class, or custom CSS to set their width.
16-
- The `.progress-bar` also requires some `role` and `aria` attributes to make it accessible, including an accessible name (using `aria-label`, `aria-labelledby`, or similar).
18+
- The `.progress` wrapper also requires a `role="progress"` and `aria` attributes to make it accessible, including an accessible name (using `aria-label`, `aria-labelledby`, or similar).
19+
- We use the inner `.progress-bar` purely for the visual bar and label.
20+
- The `.progress-bar` requires an inline style, utility class, or custom CSS to set its width.
21+
- We provide a special `.progress-stacked` class to create multiple/stacked progress bars.
1722

1823
Put that all together, and you have the following examples.
1924

2025
{{< example >}}
21-
<div class="progress">
22-
<div class="progress-bar" role="progressbar" aria-label="Basic example" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
26+
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
27+
<div class="progress-bar" style="width: 0%"></div>
2328
</div>
24-
<div class="progress">
25-
<div class="progress-bar" role="progressbar" aria-label="Basic example" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
29+
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
30+
<div class="progress-bar" style="width: 25%"></div>
2631
</div>
27-
<div class="progress">
28-
<div class="progress-bar" role="progressbar" aria-label="Basic example" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
32+
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
33+
<div class="progress-bar" style="width: 50%"></div>
2934
</div>
30-
<div class="progress">
31-
<div class="progress-bar" role="progressbar" aria-label="Basic example" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
35+
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
36+
<div class="progress-bar" style="width: 75%"></div>
3237
</div>
33-
<div class="progress">
34-
<div class="progress-bar" role="progressbar" aria-label="Basic example" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
38+
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
39+
<div class="progress-bar" style="width: 100%"></div>
3540
</div>
3641
{{< /example >}}
3742

38-
Bootstrap provides a handful of [utilities for setting width]({{< docsref "/utilities/sizing" >}}). Depending on your needs, these may help with quickly configuring progress.
43+
## Bar sizing
44+
45+
### Width
46+
47+
Bootstrap provides a handful of [utilities for setting width]({{< docsref "/utilities/sizing" >}}). Depending on your needs, these may help with quickly configuring the width of the `.progress-bar`.
3948

4049
{{< example >}}
41-
<div class="progress">
42-
<div class="progress-bar w-75" role="progressbar" aria-label="Basic example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
50+
<div class="progress" role="progressbar" aria-label="Basic example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
51+
<div class="progress-bar w-75"></div>
4352
</div>
4453
{{< /example >}}
4554

46-
## Labels
55+
### Height
4756

48-
Add labels to your progress bars by placing text within the `.progress-bar`.
57+
You only set a `height` value on the `.progress` container, so if you change that value, the inner `.progress-bar` will automatically resize accordingly.
4958

5059
{{< example >}}
51-
<div class="progress">
52-
<div class="progress-bar" role="progressbar" aria-label="Example with label" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">25%</div>
60+
<div class="progress" role="progressbar" aria-label="Example 1px high" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="height: 1px">
61+
<div class="progress-bar" style="width: 25%"></div>
62+
</div>
63+
<div class="progress" role="progressbar" aria-label="Example 20px high" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100" style="height: 20px">
64+
<div class="progress-bar" style="width: 25%"></div>
5365
</div>
5466
{{< /example >}}
5567

56-
## Height
68+
## Labels
5769

58-
We only set a `height` value on the `.progress`, so if you change that value the inner `.progress-bar` will automatically resize accordingly.
70+
Add labels to your progress bars by placing text within the `.progress-bar`.
5971

6072
{{< example >}}
61-
<div class="progress" style="height: 1px;">
62-
<div class="progress-bar" role="progressbar" aria-label="Example 1px high" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
63-
</div>
64-
<div class="progress" style="height: 20px;">
65-
<div class="progress-bar" role="progressbar" aria-label="Example 20px high" style="width: 25%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
73+
<div class="progress" role="progressbar" aria-label="Example with label" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
74+
<div class="progress-bar" style="width: 25%">25%</div>
6675
</div>
6776
{{< /example >}}
6877

@@ -71,17 +80,17 @@ We only set a `height` value on the `.progress`, so if you change that value the
7180
Use background utility classes to change the appearance of individual progress bars.
7281

7382
{{< example >}}
74-
<div class="progress">
75-
<div class="progress-bar bg-success" role="progressbar" aria-label="Success example" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
83+
<div class="progress" role="progressbar" aria-label="Success example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
84+
<div class="progress-bar bg-success" style="width: 25%"></div>
7685
</div>
77-
<div class="progress">
78-
<div class="progress-bar bg-info" role="progressbar" aria-label="Info example" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
86+
<div class="progress" role="progressbar" aria-label="Info example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
87+
<div class="progress-bar bg-info" style="width: 50%"></div>
7988
</div>
80-
<div class="progress">
81-
<div class="progress-bar bg-warning" role="progressbar" aria-label="Warning example" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
89+
<div class="progress" role="progressbar" aria-label="Warning example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
90+
<div class="progress-bar bg-warning" style="width: 75%"></div>
8291
</div>
83-
<div class="progress">
84-
<div class="progress-bar bg-danger" role="progressbar" aria-label="Danger example" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
92+
<div class="progress" role="progressbar" aria-label="Danger example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
93+
<div class="progress-bar bg-danger" style="width: 100%"></div>
8594
</div>
8695
{{< /example >}}
8796

@@ -91,13 +100,19 @@ Use background utility classes to change the appearance of individual progress b
91100

92101
## Multiple bars
93102

94-
Include multiple progress bars in a progress component if you need.
103+
You can include multiple progress components inside a container with `.progress-stacked` to create a single stacked progress bar. Note that in this case, the styling to set the visual width of the progress bar *must* be applied to the `.progress` elements, rather than the `.progress-bar`s.
95104

96105
{{< example >}}
97-
<div class="progress">
98-
<div class="progress-bar" role="progressbar" aria-label="Segment one" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
99-
<div class="progress-bar bg-success" role="progressbar" aria-label="Segment two" style="width: 30%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100"></div>
100-
<div class="progress-bar bg-info" role="progressbar" aria-label="Segment three" style="width: 20%" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100"></div>
106+
<div class="progress-stacked">
107+
<div class="progress" role="progressbar" aria-label="Segment one" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100" style="width: 15%">
108+
<div class="progress-bar"></div>
109+
</div>
110+
<div class="progress" role="progressbar" aria-label="Segment two" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" style="width: 30%">
111+
<div class="progress-bar bg-success"></div>
112+
</div>
113+
<div class="progress" role="progressbar" aria-label="Segment three" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">
114+
<div class="progress-bar bg-info"></div>
115+
</div>
101116
</div>
102117
{{< /example >}}
103118

@@ -106,20 +121,20 @@ Include multiple progress bars in a progress component if you need.
106121
Add `.progress-bar-striped` to any `.progress-bar` to apply a stripe via CSS gradient over the progress bar's background color.
107122

108123
{{< example >}}
109-
<div class="progress">
110-
<div class="progress-bar progress-bar-striped" role="progressbar" aria-label="Default striped example" style="width: 10%" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100"></div>
124+
<div class="progress" role="progressbar" aria-label="Default striped example" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
125+
<div class="progress-bar progress-bar-striped" style="width: 10%"></div>
111126
</div>
112-
<div class="progress">
113-
<div class="progress-bar progress-bar-striped bg-success" role="progressbar" aria-label="Success striped example" style="width: 25%" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100"></div>
127+
<div class="progress" role="progressbar" aria-label="Success striped example" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
128+
<div class="progress-bar progress-bar-striped bg-success" style="width: 25%"></div>
114129
</div>
115-
<div class="progress">
116-
<div class="progress-bar progress-bar-striped bg-info" role="progressbar" aria-label="Info striped example" style="width: 50%" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100"></div>
130+
<div class="progress" role="progressbar" aria-label="Info striped example" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
131+
<div class="progress-bar progress-bar-striped bg-info" style="width: 50%"></div>
117132
</div>
118-
<div class="progress">
119-
<div class="progress-bar progress-bar-striped bg-warning" role="progressbar" aria-label="Warning striped example" style="width: 75%" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100"></div>
133+
<div class="progress" role="progressbar" aria-label="Warning striped example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
134+
<div class="progress-bar progress-bar-striped bg-warning" style="width: 75%"></div>
120135
</div>
121-
<div class="progress">
122-
<div class="progress-bar progress-bar-striped bg-danger" role="progressbar" aria-label="Danger striped example" style="width: 100%" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100"></div>
136+
<div class="progress" role="progressbar" aria-label="Danger striped example" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
137+
<div class="progress-bar progress-bar-striped bg-danger" style="width: 100%"></div>
123138
</div>
124139
{{< /example >}}
125140

@@ -128,8 +143,8 @@ Add `.progress-bar-striped` to any `.progress-bar` to apply a stripe via CSS gra
128143
The striped gradient can also be animated. Add `.progress-bar-animated` to `.progress-bar` to animate the stripes right to left via CSS3 animations.
129144

130145
{{< example >}}
131-
<div class="progress">
132-
<div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" aria-label="Animated striped example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 75%"></div>
146+
<div class="progress" role="progressbar" aria-label="Animated striped example" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
147+
<div class="progress-bar progress-bar-striped progress-bar-animated" style="width: 75%"></div>
133148
</div>
134149
{{< /example >}}
135150

site/content/docs/5.2/examples/cheatsheet-rtl/index.html

+17-13
Original file line numberDiff line numberDiff line change
@@ -1397,27 +1397,31 @@ <h3>شريط التقدم</h3>
13971397

13981398
<div>
13991399
{{< example show_markup="false" >}}
1400-
<div class="progress mb-3">
1401-
<div class="progress-bar" role="progressbar" aria-label="مثال مع عنوان" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">0%</div>
1400+
<div class="progress mb-3" role="progressbar" aria-label="مثال مع عنوان" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
1401+
<div class="progress-bar">0%</div>
14021402
</div>
1403-
<div class="progress mb-3">
1404-
<div class="progress-bar bg-success w-25" role="progressbar" aria-label="مثال ناجح مع عنوان" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">25%</div>
1403+
<div class="progress mb-3" role="progressbar" aria-label="مثال ناجح مع عنوان" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
1404+
<div class="progress-bar bg-success w-25">25%</div>
14051405
</div>
1406-
<div class="progress mb-3">
1407-
<div class="progress-bar text-bg-info w-50" role="progressbar" aria-label="مثال توضيح مع عنوان" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">50%</div>
1406+
<div class="progress mb-3" role="progressbar" aria-label="مثال توضيح مع عنوان" aria-valuenow="50" aria-valuemin="0" aria-valuemax="100">
1407+
<div class="progress-bar text-bg-info w-50">50%</div>
14081408
</div>
1409-
<div class="progress mb-3">
1410-
<div class="progress-bar text-bg-warning w-75" role="progressbar" aria-label="مثال تنبيه مع عنوان" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">75%</div>
1409+
<div class="progress mb-3" role="progressbar" aria-label="مثال تنبيه مع عنوان" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100">
1410+
<div class="progress-bar text-bg-warning w-75">75%</div>
14111411
</div>
1412-
<div class="progress">
1413-
<div class="progress-bar bg-danger w-100" role="progressbar" aria-label="مثال خطر مع عنوان" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">100%</div>
1412+
<div class="progress" role="progressbar" aria-label="مثال خطر مع عنوان" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100">
1413+
<div class="progress-bar bg-danger w-100">100%</div>
14141414
</div>
14151415
{{< /example >}}
14161416

14171417
{{< example show_markup="false" >}}
1418-
<div class="progress">
1419-
<div class="progress-bar" role="progressbar" aria-label="القسم الأول - مثال افتراضي" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100"></div>
1420-
<div class="progress-bar progress-bar-striped progress-bar-animated bg-success" role="progressbar" aria-label="القسم الثاني - مثال ناجح مقلّم متحرك" style="width: 40%" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100"></div>
1418+
<div class="progress-stacked">
1419+
<div class="progress" role="progressbar" aria-label="القسم الأول - مثال افتراضي" style="width: 15%" aria-valuenow="15" aria-valuemin="0" aria-valuemax="100">
1420+
<div class="progress-bar"></div>
1421+
</div>
1422+
<div class="progress" role="progressbar" aria-label="القسم الثاني - مثال ناجح مقلّم متحرك" style="width: 40%" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100">
1423+
<div class="progress-bar progress-bar-striped progress-bar-animated bg-success"></div>
1424+
</div>
14211425
</div>
14221426
{{< /example >}}
14231427
</div>

0 commit comments

Comments
 (0)