Skip to content

Commit d77df09

Browse files
chore(Progress): updated placement and verbiage of status examples (#11988)
* chore(Progress): updated placement and verbiage of status examples * Updated snapshot * Update packages/react-core/src/components/Progress/examples/Progress.md Co-authored-by: Erin Donehoo <[email protected]> * Update packages/react-core/src/components/Progress/examples/Progress.md Co-authored-by: Erin Donehoo <[email protected]> * Update packages/react-core/src/components/Progress/examples/Progress.md Co-authored-by: Erin Donehoo <[email protected]> --------- Co-authored-by: Eric Olkowski <[email protected]> Co-authored-by: Erin Donehoo <[email protected]>
1 parent 8e9e603 commit d77df09

File tree

9 files changed

+116
-32
lines changed

9 files changed

+116
-32
lines changed

packages/react-core/src/components/MultipleFileUpload/MultipleFileUploadStatusItem.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export interface MultipleFileUploadStatusItemProps extends React.HTMLProps<HTMLL
5050
progressAriaLabel?: string;
5151
/** Associates the progress bar with it's label for accessibility purposes. Required when title not used */
5252
progressAriaLabelledBy?: string;
53+
/** Adds an accessible description to the ProgressBar via space separated list of ids. Required when helperText is passed in. */
54+
progressAriaDescribedBy?: string;
5355
/** Modifies the text announced by assistive technologies when the progress bar updates. */
5456
progressAriaLiveMessage?: string | ((loadPercentage: number) => string);
5557
/** Unique identifier for progress. Generated if not specified. */
@@ -74,6 +76,7 @@ export const MultipleFileUploadStatusItem: React.FunctionComponent<MultipleFileU
7476
progressVariant,
7577
progressAriaLabel,
7678
progressAriaLabelledBy,
79+
progressAriaDescribedBy,
7780
progressId,
7881
progressAriaLiveMessage,
7982
buttonAriaLabel = 'Remove from list',
@@ -161,6 +164,7 @@ export const MultipleFileUploadStatusItem: React.FunctionComponent<MultipleFileU
161164
variant={variant}
162165
aria-label={progressAriaLabel}
163166
aria-labelledby={progressAriaLabelledBy}
167+
aria-describedby={progressAriaDescribedBy}
164168
id={progressId}
165169
helperText={progressHelperText}
166170
/>

packages/react-core/src/components/MultipleFileUpload/examples/MultipleFileUploadBasic.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ export const MultipleFileUploadBasic: React.FunctionComponent = () => {
9696
};
9797

9898
// add helper text to a status item showing any error encountered during the file reading process
99-
const createHelperText = (file: File) => {
99+
const createHelperText = (file: File, fileIndex: number) => {
100100
const fileResult = readFileData.find((readFile) => readFile.fileName === file.name);
101101
if (fileResult?.loadError) {
102102
return (
103-
<HelperText isLiveRegion>
103+
<HelperText id={`multiple-file-upload-basic-example-help-text-${fileIndex}`} isLiveRegion>
104104
<HelperTextItem variant="error">{fileResult.loadError.toString()}</HelperTextItem>
105105
</HelperText>
106106
);
@@ -135,14 +135,15 @@ export const MultipleFileUploadBasic: React.FunctionComponent = () => {
135135
statusToggleIcon={statusIcon}
136136
aria-label="Current uploads"
137137
>
138-
{currentFiles.map((file) => (
138+
{currentFiles.map((file, index) => (
139139
<MultipleFileUploadStatusItem
140140
file={file}
141141
key={file.name}
142142
onClearClick={() => removeFiles([file.name])}
143143
onReadSuccess={handleReadSuccess}
144144
onReadFail={handleReadFail}
145-
progressHelperText={createHelperText(file)}
145+
progressHelperText={createHelperText(file, index)}
146+
progressAriaDescribedBy={`multiple-file-upload-basic-example-help-text-${index}`}
146147
/>
147148
))}
148149
</MultipleFileUploadStatus>

packages/react-core/src/components/Progress/Progress.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export interface ProgressProps extends Omit<React.HTMLProps<HTMLDivElement>, 'si
4242
'aria-label'?: string;
4343
/** Associates the ProgressBar with it's label for accessibility purposes. Required when title not used */
4444
'aria-labelledby'?: string;
45+
/** Adds an accessible description to the ProgressBar via space separated list of ids. Required when helperText is passed in. */
46+
'aria-describedby'?: string;
4547
/** Content which can be used to convey additional information about the progress component.
4648
* We recommend the helper text component as it was designed for this purpose.
4749
*/
@@ -65,7 +67,8 @@ class Progress extends Component<ProgressProps> {
6567
isTitleTruncated: false,
6668
tooltipPosition: 'top' as 'auto' | 'top' | 'bottom' | 'left' | 'right',
6769
'aria-label': null as string,
68-
'aria-labelledby': null as string
70+
'aria-labelledby': null as string,
71+
'aria-describedby': null as string
6972
};
7073

7174
id = this.props.id || getUniqueId();
@@ -89,6 +92,7 @@ class Progress extends Component<ProgressProps> {
8992
tooltipPosition,
9093
'aria-label': ariaLabel,
9194
'aria-labelledby': ariaLabelledBy,
95+
'aria-describedby': ariaDescribedBy,
9296
helperText,
9397
...props
9498
} = this.props;
@@ -107,6 +111,10 @@ class Progress extends Component<ProgressProps> {
107111
progressBarAriaProps['aria-label'] = ariaLabel;
108112
}
109113

114+
if (ariaDescribedBy) {
115+
progressBarAriaProps['aria-describedby'] = ariaDescribedBy;
116+
}
117+
110118
if (valueText) {
111119
progressBarAriaProps['aria-valuetext'] = valueText;
112120
}

packages/react-core/src/components/Progress/ProgressBar.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { css } from '@patternfly/react-styles';
44
export interface AriaProps {
55
'aria-labelledby'?: string;
66
'aria-label'?: string;
7+
'aria-describedby'?: string;
78
'aria-valuemin'?: number;
89
'aria-valuenow'?: number;
910
'aria-valuemax'?: number;
@@ -28,7 +29,7 @@ export const ProgressBar: React.FunctionComponent<ProgressBarProps> = ({
2829
value,
2930
...props
3031
}: ProgressBarProps) => (
31-
<div {...props} className={css(styles.progressBar, className)} {...progressBarAriaProps}>
32+
<div role="progressbar" {...props} className={css(styles.progressBar, className)} {...progressBarAriaProps}>
3233
<div className={css(styles.progressIndicator)} style={{ width: `${value}%` }}>
3334
<span className={css(styles.progressMeasure)}>{children}</span>
3435
</div>

packages/react-core/src/components/Progress/ProgressContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ export const ProgressContainer: React.FunctionComponent<ProgressContainerProps>
130130
)}
131131
</div>
132132
)}
133-
<ProgressBar role="progressbar" progressBarAriaProps={progressBarAriaProps} value={value}>
133+
<ProgressBar progressBarAriaProps={progressBarAriaProps} value={value}>
134134
{measureLocation === ProgressMeasureLocation.inside && `${value}%`}
135135
</ProgressBar>
136136
{helperText && <ProgressHelperText>{helperText}</ProgressHelperText>}

packages/react-core/src/components/Progress/__tests__/Generated/__snapshots__/ProgressBar.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ exports[`ProgressBar should match snapshot (auto-generated) 1`] = `
44
<DocumentFragment>
55
<div
66
class="pf-v6-c-progress__bar ''"
7+
role="progressbar"
78
>
89
<div
910
class="pf-v6-c-progress__indicator"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { render, screen } from '@testing-library/react';
2+
import { ProgressBar } from '../ProgressBar';
3+
4+
test('Does not render with aria-describedby by default', () => {
5+
render(<ProgressBar value={33} />);
6+
7+
expect(screen.getByRole('progressbar')).not.toHaveAccessibleDescription();
8+
});
9+
10+
test('Renders with aria-describedby when progressBarAriaProps is passed in', () => {
11+
render(
12+
<>
13+
<div id="test-id">Test description</div>
14+
<ProgressBar value={33} progressBarAriaProps={{ 'aria-describedby': 'test-id' }} />
15+
</>
16+
);
17+
18+
expect(screen.getByRole('progressbar')).toHaveAccessibleDescription('Test description');
19+
});

packages/react-core/src/components/Progress/examples/Progress.md

Lines changed: 67 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,75 +8,119 @@ propComponents: ['Progress']
88
import { useState } from 'react';
99

1010
## Examples
11+
1112
### Basic
13+
1214
```ts file="./ProgressBasic.tsx"
15+
1316
```
1417

1518
### Small
19+
1620
```ts file="./ProgressSmall.tsx"
21+
1722
```
1823

1924
### Large
25+
2026
```ts file="./ProgressLarge.tsx"
21-
```
2227

23-
### Outside
24-
```ts file="./ProgressOutside.tsx"
2528
```
2629

27-
### Inside
28-
```ts file="./ProgressInside.tsx"
29-
```
30+
### Outside
3031

31-
### Success
32-
```ts file="./ProgressSuccess.tsx"
33-
```
32+
```ts file="./ProgressOutside.tsx"
3433

35-
### Failure
36-
```ts file="./ProgressFailure.tsx"
3734
```
3835

39-
### Warning
40-
```ts file="./ProgressWarning.tsx"
41-
```
36+
### Inside
4237

43-
### Inside success
44-
```ts file="./ProgressInsideSuccess.tsx"
45-
```
38+
```ts file="./ProgressInside.tsx"
4639

47-
### Outside failure
48-
```ts file="./ProgressOutsideFailure.tsx"
4940
```
5041

5142
### Single line
43+
5244
```ts file="./ProgressSingleLine.tsx"
45+
5346
```
5447

5548
### Without measure
49+
5650
```ts file="./ProgressWithoutMeasure.tsx"
57-
```
5851

59-
### Failure without measure
60-
```ts file="./ProgressFailureWithoutMeasure.tsx"
6152
```
6253

63-
6454
### Finite step
55+
6556
```ts file="./ProgressFiniteStep.tsx"
57+
6658
```
6759

6860
### Progress with step instructions
61+
6962
```ts file="./ProgressStepInstruction.tsx"
63+
7064
```
7165

7266
### Truncate title
67+
7368
```ts file="./ProgressTruncateTitle.tsx"
69+
7470
```
7571

7672
### Title outside of progress bar
73+
7774
```ts file="./ProgressTitleOutsideOfProgressBar.tsx"
75+
7876
```
7977

8078
### Helper text
79+
8180
```ts file="./ProgressHelperText.tsx"
81+
82+
```
83+
84+
## Status examples
85+
86+
When conveying status, you should ensure:
87+
88+
- There is visible helper text that explains the status.
89+
- The helper text includes the status icon, as seen in our [basic helper text example](/components/helper-text#basic).
90+
- The helper text is linked to the `<Progress>` component via the `aria-describedby` property, as seen in the [progress helper text example](#helper-text).
91+
92+
### Success
93+
94+
```ts file="./ProgressSuccess.tsx"
95+
96+
```
97+
98+
### Failure
99+
100+
```ts file="./ProgressFailure.tsx"
101+
102+
```
103+
104+
### Warning
105+
106+
```ts file="./ProgressWarning.tsx"
107+
108+
```
109+
110+
### Inside success
111+
112+
```ts file="./ProgressInsideSuccess.tsx"
113+
114+
```
115+
116+
### Outside failure
117+
118+
```ts file="./ProgressOutsideFailure.tsx"
119+
120+
```
121+
122+
### Failure without measure
123+
124+
```ts file="./ProgressFailureWithoutMeasure.tsx"
125+
82126
```

packages/react-core/src/components/Progress/examples/ProgressHelperText.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export const ProgressHelperText: React.FunctionComponent = () => {
2525
const helperTextVariant = selectedVariant === 'danger' ? 'error' : selectedVariant;
2626

2727
const helperText = (
28-
<HelperText>
28+
<HelperText id="progress-helper-text-example-help-text">
2929
<HelperTextItem variant={helperTextVariant}>
3030
{`${formatVariantName(selectedVariant)} variant is being displayed`}
3131
</HelperTextItem>
@@ -36,7 +36,13 @@ export const ProgressHelperText: React.FunctionComponent = () => {
3636
<>
3737
{variantOptions}
3838
<br />
39-
<Progress value={33} title="Title" helperText={helperText} variant={selectedVariant} />
39+
<Progress
40+
aria-describedby="progress-helper-text-example-help-text"
41+
value={33}
42+
title="Title"
43+
helperText={helperText}
44+
variant={selectedVariant}
45+
/>
4046
</>
4147
);
4248
};

0 commit comments

Comments
 (0)