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

Add progressively enhanced File Upload component #5305

Draft
wants to merge 75 commits into
base: main
Choose a base branch
from

Conversation

querkmachine
Copy link
Member

@querkmachine querkmachine commented Sep 10, 2024

As part of post-audit investigations, a spike into layering a new UI onto the File upload component that should be a bit more friendly to assistive technologies. alphagov/govuk-design-system#4031

Note: This hasn't actually been tested across browsers and ATs yet,

Changes

  • Progressively enhances the file input of the File upload component with a custom button and file selection display.
    • This new UI localisable. This adds the potential for buttons to better describe what needs uploading.
    • As much as possible, this new UI behaves similarly to the browser's native controls (e.g. can click on the label or input text to activate the component; supports multiple, accepts and capture attributes; etc.)
  • Adds a visual drop zone if a file is dragged over the input.

Thoughts

  • There are some features that are not supported yet. For example, the button will still appear useable even if the underlying input has been disabled.
  • The native file input is visually hidden but is still exposed to screen readers. I wasn't sure if I could (or should) hide it from them, as it may contain context that the 'enhanced' controls do not. Further testing needed.
  • This has been developed to pretty closely resemble native file inputs as they appear in Chromium browsers. We may be interested in styling them more similarly to other form inputs (e.g. having a black border around it.)
  • The visual drop zone currently only appears when dragging over the input itself. It may be preferable for it to appear if a file is dragged over anywhere on the page.

@querkmachine querkmachine self-assigned this Sep 10, 2024
Copy link

github-actions bot commented Sep 10, 2024

📋 Stats

File sizes

File Size
dist/govuk-frontend-development.min.css 121.32 KiB
dist/govuk-frontend-development.min.js 47.92 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 102.26 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 96.03 KiB
packages/govuk-frontend/dist/govuk/all.mjs 1.28 KiB
packages/govuk-frontend/dist/govuk/component.mjs 1.67 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 121.31 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 47.91 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.55 KiB
packages/govuk-frontend/dist/govuk/init.mjs 6.89 KiB

Modules

File Size (bundled) Size (minified)
all.mjs 90.25 KiB 45.48 KiB
accordion.mjs 26.58 KiB 13.41 KiB
button.mjs 9.09 KiB 3.79 KiB
character-count.mjs 25.37 KiB 10.91 KiB
checkboxes.mjs 7.76 KiB 3.42 KiB
error-summary.mjs 10.99 KiB 4.55 KiB
exit-this-page.mjs 20.2 KiB 10.34 KiB
file-upload.mjs 21.08 KiB 11.07 KiB
header.mjs 6.41 KiB 3.22 KiB
notification-banner.mjs 9.35 KiB 3.71 KiB
password-input.mjs 18.16 KiB 8.34 KiB
radios.mjs 6.76 KiB 2.98 KiB
service-navigation.mjs 6.39 KiB 3.26 KiB
skip-link.mjs 6.34 KiB 2.76 KiB
tabs.mjs 11.99 KiB 6.67 KiB

View stats and visualisations on the review app


Action run for 85e94b6

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

This comment was marked as resolved.

@selfthinker
Copy link

I've started testing this today. But I've only tested with Dragon so far.

Unfortunately it doesn't work. Roughly 9 out of 10 times saying "click choose file" or "click button" only focused on the button but didn't open the file dialog. And weirdly 1 out of 10 times it did. But I didn't do anything differently between when it did and when it didn't.

When we've figured out why this is happening I will test again, including in other assistive technologies.

@owenatgov owenatgov force-pushed the spike-enhanced-file-upload branch from 8fe1f08 to d411a91 Compare October 4, 2024 11:00
@owenatgov
Copy link
Contributor

Rebased this whilst I do some local testing

@edwardhorsford
Copy link
Contributor

Just in case it's helpful - we had a styled upload button on the passport service - which has presumably been tested by DAC multiple times.

@querkmachine
Copy link
Member Author

@edwardhorsford Do you know if it was tested in Dragon NaturallySpeaking and, if so, whether it exhibited the same issues described by @selfthinker?

@edwardhorsford
Copy link
Contributor

@edwardhorsford Do you know if it was tested in Dragon NaturallySpeaking and, if so, whether it exhibited the same issues described by @selfthinker?

I assume it was tested with it as DAC did the testing. But I don't recall more than that. You could try on the live service to see how it works now...

@querkmachine
Copy link
Member Author

Adding aria-hidden to the input is apparently ignored by Chromium and raises an error in the console.

Blocked aria-hidden on a <input> element because the element that just received focus must not be hidden from assistive technology users. Avoid using aria-hidden on a focused element or its ancestor. Consider using the inert attribute instead, which will also prevent focus. For more details, see the aria-hidden section of the WAI-ARIA specification at https://w3c.github.io/aria/#aria-hidden.

tabindex="-1" alone probably suffices for stopping tabbing but I'm not sure if it can prevent keyboard navigation entirely, especially of the kind that screenreaders do which is on a level not easily detected by webpages.

@selfthinker
Copy link

DAC's solution was using the disabled attribute.
But they were partly using it to show the uploaded file.

@querkmachine querkmachine force-pushed the spike-enhanced-file-upload branch from 6ab7ef8 to f2bccb3 Compare October 21, 2024 08:51
romaricpascal and others added 10 commits February 10, 2025 12:00
Simplify selectors in `index.scss` of File Upload by adding new
`govuk-file-upload--enhanced` class. Add `govuk-file-upload--enhanced`
to `input` element in Javascript initialisation.
The element is its own block not a descendant of `.govuk-file-upload`. Renames its descendants to make them elements of `.govuk-file-upload-button` rather than of `.govuk-file-upload`.
Helps understand the changes that happen on hover
Use SCSS nesting to simplify selectors.
Improve naming of File Upload classes and regroup state styles
@romaricpascal romaricpascal changed the title Add progressively enhanced file upload component Add progressively enhanced File Upload component Feb 10, 2025
- `input` element hidden during File Upload enhancement initialisation
- `button` listens for drop event and updates status and input
accordingly
- Remove `--enhanced` and `-dragging` classes for `govuk-file-upload`
- Remove JS in File Upload  that adds the removed classes on initialisation
and drag
- Update input selector in File Upload test
Fix functionality of enhanced File Upload when no CSS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants