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

Native file upload component #1807

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open

Native file upload component #1807

wants to merge 33 commits into from

Conversation

amazingphilippe
Copy link
Contributor

@amazingphilippe amazingphilippe commented Apr 16, 2024

Summary | Résumé

For cds-snc/notification-planning#1229

Fundamentally reconsiders how we do file uploaders.

More native, with a bit of css.

Can't be localized: The browser's default file uploader is sort of a web component, and you can't slot in your own text strings.

At the minimum, lets do some user testing with this PR.

Test instructions | Instructions pour tester la modification

  1. Review file upload on the logo upload screen (Settings>Branding>Other>New)
  2. Review file upload on the send flow (Template>Send>Many)

There will be the following visual changes:

Logo before:
image
Logo after:
image

Check the following behaviours for Logo form:

  1. File description updates on upload with file name, size
  2. Validation occurs when input is left empty

Send before:
image

Send after:
image

Check the following on the send flow:

  1. Input submits the form - Throws an error on review apps -
  2. If you're testing locally, you miught briefly catch a "cancel upload" button. Its weird, but its expected

@amazingphilippe amazingphilippe changed the title simplify file_upload components and file upload in branding form Native file upload component Apr 16, 2024
Copy link

Copy link
Member

@andrewleith andrewleith left a comment

Choose a reason for hiding this comment

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

Looks good to me overall. The request branding page still works, although the missing data-testid will cause the tests to fail so just requesting that you add that back.

@@ -23,7 +23,7 @@
const input_img = document.querySelector("input.file-upload-field");
const alt_en = document.getElementById("alt_text_en");
const alt_fr = document.getElementById("alt_text_fr");
const message = document.querySelector(".preview .message");
const message = document.querySelector("#file-description");
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const message = document.querySelector("#file-description");
const message = document.getElementById("file-description");

{% endif %}

<div class="form-group">
{{ form.file(**{ 'class': 'file-upload-field', 'accept': 'image/png', 'data_testid': 'brand_image', 'aria-labelledby': 'file-description', 'data-error-msg': _('You must select a file to continue') }) }}
Copy link
Member

Choose a reason for hiding this comment

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

We need to have the data-testid brand_image for the tests to continue to pass. Unfortunately the tests still arent merged so this would have been easy to miss.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can add it back. The testid needs to be on the input element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added testid as file field optional attribute. defaults to test_field-name

Copy link
Contributor

@whabanks whabanks left a comment

Choose a reason for hiding this comment

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

I noticed a couple of issues:

  1. On the branding upload page I am unable to "click" the File Upload button with the keyboard both with and without a screen reader.
  2. When using a screen reader the File Upload button is not read out
REC-20240529093739.mp4
  1. On the Prepare a spreadsheet page the File upload button cannot be navigated to via the keyboard.
  2. There's some extra hint text showing the mime types / file extensions accepted that I don't see captured in your original screen shots, was this an intentional change?
REC-20240529102806.mp4

@amazingphilippe
Copy link
Contributor Author

Yikes! Thanks Will for spotting these issues.

  1. I've re-enabled to focus on the actual input. This will re-enable the default keyboard interaction.
  2. I placed focus styles on :focus-within since our input is invisible. I had to rearrange a bit the label and other form group instructions. (which also solved another bug with the focus indicator on an invalid file input)
  3. I've made sure to name the macro attributes when calling it. The accept was being interpolated to hint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants