Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Unreleased
- Layout: The "Delete Account" confirmation page has a new layout consistent with other content pages. (#5857)

### Accessibility
- Document capture: The image file field label is no longer set to file names so that screen readers do not read the filenames to users. (#5858)

### Bug Fixes Users Might Notice

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,15 @@ function FileInput(props, ref) {
}

/**
* @param {string} fileLabel String velue of the label for input to display
* @param {Blob|string|null|undefined} fileValue File or string for which to generate label.
*/
function getLabelFromValue(fileValue) {
function getLabelFromValue(fileLabel, fileValue) {
if (fileValue instanceof window.File) {
return fileValue.name;
return `${fileLabel} - ${fileValue.name}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we include the label in all of the possible return paths of this function, not just the one where we know the file's name?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I added a label to the second return statement. The last return path doesn't need it. I tested with a screen reader and it looks like the label field will take precedence over that.

}
if (fileValue) {
return t('doc_auth.forms.captured_image');
return `${fileLabel} - ${t('doc_auth.forms.captured_image')}`;
}
return '';
}
Expand Down Expand Up @@ -319,7 +320,7 @@ function FileInput(props, ref) {
id={inputId}
className="usa-file-input__input"
type="file"
aria-label={getLabelFromValue(value)}
aria-label={getLabelFromValue(label, value)}
aria-busy={isValuePending}
onChange={onChangeIfValid}
capture={capture}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,12 @@ describe('document-capture/components/file-input', () => {
expect(queryByAriaLabel).to.exist();
});

it('has aria-label same as file name', () => {
it('has aria-label with label and filename', () => {
const fileName = 'file2.jpg';
const file2 = new window.File([file], fileName);
const { getByLabelText } = render(<FileInput label="File" value={file2} />);

const queryByAriaLabel = getByLabelText(fileName);
const queryByAriaLabel = getByLabelText(`File - ${fileName}`);

expect(queryByAriaLabel).to.exist();
});
Expand All @@ -258,7 +258,7 @@ describe('document-capture/components/file-input', () => {
/>,
);

const queryByAriaLabel = getByLabelText('doc_auth.forms.captured_image');
const queryByAriaLabel = getByLabelText(`File - ${'doc_auth.forms.captured_image'}`);

expect(queryByAriaLabel).to.exist();
});
Expand Down