Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

amyleadem
Copy link
Contributor

@amyleadem amyleadem commented Apr 3, 2023

Summary

Improved the file input experience for voice command and screen reader users. Voice command users can now more easily interact with the component by speaking the visible instructions text. Additionally, screen reader users now have access to both the visible instructions text (in the aria-label) and the file selection status (in a newly created screen reader-only element).

Breaking change

This is not a breaking change.
All changes have been handled dynamically.

Related issue

Closes #5192

As a future enhancement, issue #5238 will create data attributes that will allow users to customize the status and instructions text.

Related pull requests

Changelog update: uswds/uswds-site#2088

Preview link

Preview link: File input

Problem statement

Users of assistive technologies should be able to intuitively access all form elements, understand what action they should take, and receive feedback so that they can confirm that the information they have added is correct. However, the file input component presents problems for both screen reader and voice command users:

Voice command issues

Because of file input's structure, voice command does not work in an intuitive way. A user would expect to vocalize the text shown on screen as part of a "Click" command. For file input, this would mean the user would expect to say something like "Click drag file here or choose from folder" or ""Click choose from folder" to interact with the file input. However, neither of these work because the accessibility tree does not include this information.

Screen readers issues

Screen reader users do not have access to the instructions text ("Drag file here or choose from folder"). Instead, the aria-label provides feedback on the file selection status. This is insufficient information for interaction. The default aria-label "no file selected" does not clearly communicate what the input is or what the user should do, which can lead to confusion.

Solution

To allow voice command users to easily access the file input component, we should make sure the input aria-label matches the visible text as the status changes.

To allow screen reader users to continue to confirm their file selection, we should move the file status from the aria-label to a dynamically created sr-only element.

Major changes

  1. Moved the file status update from the input aria-label to a new sr-only element.
  2. The input aria-label now matches the visible instruction text so that voice command users can access the component with intuitive commands
  3. Broke out buildFileInput() into separate functions: createTargetArea and createVisibleInstructions
  4. Standardized and added clarity to JSDoc comments

Possible future enhancements

Converting the CTA text ("choose from folder", "change file") from a <span> element to a <button> element might improve consistency in Voice Command software. It could also give an alternative method for voice control users so that they can highlight all interactive elements on the page and select the element they want to click.

Testing and review

Accessibility:

  • Confirm that the screen reader experience is intuitive and makes sense
  • Confirm that you can open the file input dialog via voice command (If available. It would be helpful to know which tools you used)
  • When file status changes, confirm that the status update is read on a screen reader

Developers:

The following items should be confirmed:

  • Confirm that the aria-label on the input matches the visible instruction text:
    • Default text = “Drag file here or choose from folder”
    • One file selected = “Change file”
    • More than one file selected = “Change files”
    • File removed = “Drag file here or choose from folder”
  • Confirm that the status element (.usa-sr-only) updates correctly when:
    • One file selected = "You have selected the file: [fileName]"
    • More than one file selected = "You have selected [x] files: [fileName], [fileName], etc"
    • File removed = "No file selected."
  • In the multiple inputs test page, confirm that each input creates unique status update.
  • Confirm no visual regressions
  • Confirm no behavioral regressions
  • Confirm the JavaScript is well-structured and makes sense
  • [ADDITION] Confirm that status element is not created for disabled or aria-disabled file inputs

@amyleadem amyleadem changed the title USWDS - File input: Fix issues with voice comman USWDS - File input: Fix issues with voice command Apr 5, 2023
@amyleadem
Copy link
Contributor Author

amyleadem commented Apr 18, 2023

@briandeconinck I have created a prototype here that changes the aria-label on the file input to match the visible instruction text ("Drag file here or choose from folder").

This is still a work in progress but before I get too far down the road, would you be able to test this prototype to see if you can access the input by speaking the visible text via Dragon Naturally Speaking (and/or any other voice control software you might have access to)?

Please let me know if you have questions!

@briandeconinck
Copy link

Hi Amy! Sorry for the slow reply.

I see the updated aria-label and I believe it should work... but when I actually test it, it's hit-or-miss. Digging through some 7+ year old forum threads and it sounds like there's some inconsistency with how Dragon plays with file inputs. But the aria-label is giving me a match at least some of the time, with both the full text and just the "choose from folder" substring. Accounting for odd behavior with Dragon, that might be good enough. 🤷

I will note that since the instruction text has the fake-link styling, the command "Click link" still doesn't highlight the input as an option, which would typically be the next thing I try if "Click choose from folder" doesn't get a match. Maybe make it an actual link or button with a JS action to map it to the input? I believe even if it's removed from the tab order with tabindex="-1" it should still work with Dragon, but I haven't tested that.

Up to you whether you want to pursue that. What you have here is definitely an improvement and should work most of the time for Dragon users (again, accounting for possible Dragon weirdness).

@amyleadem
Copy link
Contributor Author

Thanks for the response, @briandeconinck! Your test results are helpful. Since we aren't hitting consistent results with aria-label in Dragon and other voice command methods, I am going to explore if there are alternate paths here. Thanks for the suggestions and I appreciate you taking the time! I'll tag you again if there are any updates.

@amyleadem amyleadem requested a review from mejiaj May 10, 2023 22:00
@amyleadem
Copy link
Contributor Author

amyleadem commented May 17, 2023

Note: considering removing the SR-only element readout if file input is disabled. Might determine that no action is needed or it could be a follow-up issue. Will investigate tomorrow. There is no need for this effort to interrupt any reviews in process.

@amyleadem
Copy link
Contributor Author

amyleadem commented May 18, 2023

I added a check for the disabled attribute before generating the sr-only status message. Let me know if you see any issues with this.

Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

Focused on code in this review and added some comments. Overall no issues, but some minor areas we can improve.

Mainly, saving the default aria label in code and possible duplicate check on disabled state.

/Edge\/\d./i.test(navigator.userAgent)
) {
fileInputParent.querySelector(`.${DRAG_TEXT_CLASS}`).outerHTML = "";
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Future task

We could remove this IE11/Edge check any time.
image

HTMLElement: drop event - Web APIs | MDN

Copy link
Contributor Author

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

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

@mejiaj Thanks for the helpful review! I have addressed all comments. Please let me know if you have questions.

@amyleadem amyleadem requested a review from mejiaj May 22, 2023 22:12
On enhance file input will add a class if the component either has aria-disabled or disabled attribute.
@amyleadem
Copy link
Contributor Author

@mejiaj I confirmed that your update adds the disabled class as expected when either disabled or aria-disabled is present on the input element. Thanks for cleaning up the disabled behavior so that the attributes aren't touched on init. Appreciate it!

Will you let me know if you see anything else?

Copy link
Contributor

@mejiaj mejiaj left a comment

Choose a reason for hiding this comment

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

Code looks good, I just have a comment on addPreviewHeading(). This function adds a description for screen readers for how many files and their names.

On voiceover this only gets read once after upload. We could improve this by having it be read on focus as a fast follow-up.

* @param {HTMLInputElement} fileInputEl - The input element.
* @param {Object} fileNames - The selected files found in the fileList object.
*/
const addPreviewHeading = (fileInputEl, fileNames) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function adds text describing:

  • How many files
  • Which files have been uploaded

So far I've only gotten it to read after initial upload. If I move to another area and comeback it doesn't get read on VoiceOver Chromium 113.

Possible Future enhancements:

  1. Add a unique ID to this message and tie it to the component via aria-labelledby [MDN on aria-labelledby]
  2. Move the preview heading text so it always gets read.
  3. Dynamically update the aria-label

Move the preview heading text example

file-input-label.mp4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @mejiaj. I've opened #5304 to start looking into this. I will begin investigating as a fast follow-up.

Copy link
Contributor

@thisisdano thisisdano left a comment

Choose a reason for hiding this comment

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

Nice work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

USWDS - Bug: File input issues with voice command and screen readers

6 participants