Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(MultipleFileUpload): add aria live region to internal Progress #8242

Merged
merged 4 commits into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface MultipleFileUploadStatusItemProps extends React.HTMLProps<HTMLL
progressAriaLabel?: string;
/** Associates the progress bar with it's label for accessibility purposes. Required when title not used */
progressAriaLabelledBy?: string;
/** Modifies the text announced by assistive technologies when the progress bar updates. */
progressAriaLiveMessage?: string | ((loadPercentage: number) => string);
/** Unique identifier for progress. Generated if not specified. */
progressId?: string;
}
Expand All @@ -71,6 +73,7 @@ export const MultipleFileUploadStatusItem: React.FunctionComponent<MultipleFileU
progressAriaLabel,
progressAriaLabelledBy,
progressId,
progressAriaLiveMessage,
buttonAriaLabel = 'Remove from list',
...props
}: MultipleFileUploadStatusItemProps) => {
Expand Down Expand Up @@ -139,6 +142,13 @@ export const MultipleFileUploadStatusItem: React.FunctionComponent<MultipleFileU
<li className={css(styles.multipleFileUploadStatusItem, className)} {...props}>
<div className={styles.multipleFileUploadStatusItemIcon}>{fileIcon || <FileIcon />}</div>
<div className={styles.multipleFileUploadStatusItemMain}>
<div className="pf-screen-reader" aria-live="polite">
{progressAriaLiveMessage &&
typeof progressAriaLiveMessage === 'function' &&
progressAriaLiveMessage(+loadPercentage.toFixed(2))}
{progressAriaLiveMessage && typeof progressAriaLiveMessage === 'string' && progressAriaLiveMessage}
{!progressAriaLiveMessage && `Progress value is ${progressValue || Math.floor(loadPercentage)}%.`}
</div>
<Progress
title={title}
value={progressValue || loadPercentage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,39 @@ describe('MultipleFileUploadStatusItem', () => {
expect(asFragment()).toMatchSnapshot();
});

test('renders custom file name/size/icon when passed', () => {
test('renders custom file name/size/icon/progressAriaLiveMessage when passed', () => {
const testFile = new File(['foo'], 'testFile.txt');
const { asFragment } = render(
<MultipleFileUploadStatusItem
file={testFile}
fileIcon={<FileImageIcon />}
fileName="testCustomFileName.txt"
fileSize={42}
progressId="test-progress-id"
progressAriaLiveMessage="test message"
/>
);

expect(asFragment()).toMatchSnapshot();
});

test('renders custom function progressAriaLiveMessage when passed', () => {
const testFile = new File(['foo'], 'testFile.txt');
const { asFragment } = render(
<MultipleFileUploadStatusItem
file={testFile}
fileIcon={<FileImageIcon />}
fileName="testCustomFileName.txt"
fileSize={42}
progressId="test-progress-id"
progressAriaLiveMessage={loadPercentage => `test message ${loadPercentage}`}
/>
);

expect(asFragment()).toMatchSnapshot();
});

test('rendersdefault progressAriaLiveMessage when nothing is passed', () => {
const testFile = new File(['foo'], 'testFile.txt');
const { asFragment } = render(
<MultipleFileUploadStatusItem
Expand Down
Loading