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 44 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 120.14 KiB
dist/govuk-frontend-development.min.js 47.01 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 100.92 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 94.8 KiB
packages/govuk-frontend/dist/govuk/all.mjs 1.32 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend-component.mjs 1.74 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.css 120.13 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 47 KiB
packages/govuk-frontend/dist/govuk/i18n.mjs 5.55 KiB
packages/govuk-frontend/dist/govuk/init.mjs 7.5 KiB

Modules

File Size (bundled) Size (minified)
all.mjs 88.93 KiB 44.54 KiB
accordion.mjs 26.58 KiB 13.41 KiB
button.mjs 9.09 KiB 3.78 KiB
character-count.mjs 25.39 KiB 10.9 KiB
checkboxes.mjs 7.81 KiB 3.42 KiB
error-summary.mjs 10.99 KiB 4.54 KiB
exit-this-page.mjs 20.2 KiB 10.34 KiB
file-upload.mjs 19.5 KiB 10.13 KiB
header.mjs 6.46 KiB 3.22 KiB
notification-banner.mjs 9.35 KiB 3.7 KiB
password-input.mjs 18.24 KiB 8.33 KiB
radios.mjs 6.81 KiB 2.98 KiB
service-navigation.mjs 6.44 KiB 3.26 KiB
skip-link.mjs 6.4 KiB 2.76 KiB
tabs.mjs 12.04 KiB 6.67 KiB

View stats and visualisations on the review app


Action run for 2e256f5

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
We check that `$root` is an input with `type="file"` so it will have a `files`
property that's not null.
Remove comments ignoring TypeScript or linting errors
- Only show the dropzone when the user drags into it rather than when entering the document. This will prevent multiple announcements when we add feedback for screenreaders, in case there's multiple `FileUpload`s on the page
- Add a test to check if the user is dragging files before showing dropzone
- Fix disappearance of the dropzone due to many `dragleave` events being triggered as user drags over the different elements inside the wrapper
- Separate the handler of `drop` event as it doesn't need the same complexity as the `dragleave` one before hiding the dropzone.

The component still relies on the native `<input>` receiving the files being dropped, as it ensures a `change` event gets triggered on drop (which we'd have to simulate if setting its `files` properties programmatically).
It happened when dragging from the button to the span or the opposite,
because Safari does not fill the `relatedTarget` on `dragleave`, making
our code believe user had left the window.

To accomodate for that, we use `dragenter` to also hide the drop zone
when entering an element that's not the wrapper.

This may still leave a gap where the component is at the edge of the viewport,
either because of scrolling or in a iframe. Will explore in next commit.
Announces when users enter or leave the drop zone.

Note: this seems to only be announced by Voice Over
when Safari is in the foreground, even when using `aria-live="assertive"`
patrickpatrickpatrick and others added 5 commits January 21, 2025 15:37
Button replaces entire native file upload. This replacement has a within
it a "psuedo button" span that has the same focus, hover and active
behaviour as a secondary button.
Hide the button text entirely from screen reader and add button content
as `aria-label`. This should lead to more consistent reading out of the
button content.
- Tests now use the correct selector for when the input has been visually
replaced by the button.
- Added tests for button `aria-label`.
- Added test for clicking on different elements within button
Adjustments made to the the file upload so that in the event of an error
the correct part of the page can be linked to.
Use button element for entire input replacement
This ensure hints and errors are associated with the `<button>` for assistive technology users.
@romaricpascal romaricpascal changed the title [SPIKE] Explore progressively enhanced file upload component Add progressively enhanced file upload component Jan 27, 2025
The option also controls the rendering of the translation strings,
as they're not needed if the component does not run JavaScript enhancements.

In the unlikely case that someone would want the translation strings,
but not run our JavaScript enhancements, we could add a new option. In the meantime,
the `attributes` option allows them to manually add the data attributes.
As JavaScript enhancements are now optional, the examples loaded on the page needed to be `javascript`.
Otherwise the `render` helper would throw as it'd try to initialise the component on `null`,
as `document.querySelectorAll('govuk-file-upload')` wouldn't find any element.
The `render` helper assumed all examples of a component for which
a JavaScript component exist would have a `data-module` and as such
forced initialising a JavaScript component when no element with the appropriate
`data-module` was found on the page.

This behaviour is handy to spot if a component suddenly stops rendering `data-module`,
so we don't want to change the `render` function. For the File Upload,
we can decide whether the error is relevant in the test, based on whether the `javascript`
macro option is set.
The `default` example is now back to rendering the native component,
so we'll want a test for the JavaScript enhanced version
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.

Investigate solution for operating the file upload component with Dragon
8 participants