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

File Upload disabled clean-up #5719

Merged
merged 3 commits into from
Feb 13, 2025

Conversation

patrickpatrickpatrick
Copy link
Contributor

@patrickpatrickpatrick patrickpatrickpatrick commented Feb 11, 2025

What

  • Add back border to File Upload drop zone
  • Don't add --dragging to the the File Upload button if it is disabled
  • Don't announce Left drop zone if the File Upload button is disabled

Why

Black border when drag zone active had disappeared, possibly from refactoring the CSS in prior commit.

Refactoring had resulted in the dropzone not behaving as expected when button was disabled.

@patrickpatrickpatrick patrickpatrickpatrick changed the base branch from main to spike-enhanced-file-upload February 11, 2025 15:39
Copy link

github-actions bot commented Feb 11, 2025

📋 Stats

File sizes

File Size
dist/govuk-frontend-development.min.css 121.49 KiB
dist/govuk-frontend-development.min.js 48.06 KiB
packages/govuk-frontend/dist/govuk/all.bundle.js 102.42 KiB
packages/govuk-frontend/dist/govuk/all.bundle.mjs 96.21 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 121.47 KiB
packages/govuk-frontend/dist/govuk/govuk-frontend.min.js 48.05 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.39 KiB 45.48 KiB
accordion.mjs 26.63 KiB 13.41 KiB
button.mjs 9.14 KiB 3.79 KiB
character-count.mjs 25.42 KiB 10.91 KiB
checkboxes.mjs 7.81 KiB 3.42 KiB
error-summary.mjs 11.04 KiB 4.55 KiB
exit-this-page.mjs 20.25 KiB 10.34 KiB
file-upload.mjs 21.13 KiB 11.07 KiB
header.mjs 6.46 KiB 3.22 KiB
notification-banner.mjs 9.4 KiB 3.71 KiB
password-input.mjs 18.21 KiB 8.34 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 7e06c98

Copy link

github-actions bot commented Feb 11, 2025

JavaScript changes to npm package

diff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
index 17354224d..f6220464f 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
@@ -782,11 +782,11 @@ class FileUpload extends ConfigurableComponent {
         })), this.$root.insertAdjacentElement("afterbegin", s), this.$input.setAttribute("tabindex", "-1"), this.$input.setAttribute("aria-hidden", "true"), this.$button = s, this.$status = r, this.$input.addEventListener("change", this.onChange.bind(this)), this.updateDisabledState(), this.observeDisabledState(), this.$announcements = document.createElement("span"), this.$announcements.classList.add("govuk-file-upload-announcements"), this.$announcements.classList.add("govuk-visually-hidden"), this.$announcements.setAttribute("aria-live", "assertive"), this.$root.insertAdjacentElement("afterend", this.$announcements), this.$button.addEventListener("drop", this.onDrop.bind(this)), document.addEventListener("dragenter", this.updateDropzoneVisibility.bind(this)), document.addEventListener("dragenter", (() => {
             this.enteredAnotherElement = !0
         })), document.addEventListener("dragleave", (() => {
-            this.enteredAnotherElement || (this.hideDraggingState(), this.$announcements.innerText = this.i18n.t("leftDropZone")), this.enteredAnotherElement = !1
+            this.enteredAnotherElement || this.$button.disabled || (this.hideDraggingState(), this.$announcements.innerText = this.i18n.t("leftDropZone")), this.enteredAnotherElement = !1
         }))
     }
     updateDropzoneVisibility(t) {
-        t.target instanceof Node && (this.$root.contains(t.target) ? t.dataTransfer && isContainingFiles(t.dataTransfer) && (this.$button.classList.contains("govuk-file-upload-button--dragging") || (this.showDraggingState(), this.$announcements.innerText = this.i18n.t("enteredDropZone"))) : this.$button.classList.contains("govuk-file-upload-button--dragging") && (this.hideDraggingState(), this.$announcements.innerText = this.i18n.t("leftDropZone")))
+        this.$button.disabled || t.target instanceof Node && (this.$root.contains(t.target) ? t.dataTransfer && isContainingFiles(t.dataTransfer) && (this.$button.classList.contains("govuk-file-upload-button--dragging") || (this.showDraggingState(), this.$announcements.innerText = this.i18n.t("enteredDropZone"))) : this.$button.classList.contains("govuk-file-upload-button--dragging") && (this.hideDraggingState(), this.$announcements.innerText = this.i18n.t("leftDropZone")))
     }
     showDraggingState() {
         this.$button.classList.add("govuk-file-upload-button--dragging")

Action run for 7e06c98

Copy link

github-actions bot commented Feb 11, 2025

Stylesheets changes to npm package

diff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.css b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.css
index 27286ad40..5bef099c0 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.css
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.css
@@ -3511,6 +3511,11 @@ screen and (forced-colors:active) {
     background-color: #d2e2f1
 }
 
+.govuk-file-upload-button--dragging {
+    border-style: solid;
+    border-color: #0b0c0c
+}
+
 .govuk-file-upload-button--dragging.govuk-file-upload-button {
     background-color: #c1c3c5
 }
@@ -3519,19 +3524,15 @@ screen and (forced-colors:active) {
     background-color: #f3f2f1
 }
 
-.govuk-file-upload-button--dragging:not(:disabled) {
-    border-color: #8e9092
-}
-
-.govuk-file-upload-button--dragging:not(:disabled) .govuk-file-upload-button__pseudo-button {
-    background-color: #dbdad9
-}
-
 .govuk-file-upload-button--dragging.govuk-file-upload-button--empty .govuk-file-upload-button__pseudo-button,
 .govuk-file-upload-button--dragging.govuk-file-upload-button--empty:not(:disabled) .govuk-file-upload-button__status {
     background-color: #fff
 }
 
+.govuk-file-upload-button--dragging .govuk-file-upload-button__pseudo-button {
+    background-color: #dbdad9
+}
+
 .govuk-footer {
     font-family: GDS Transport, arial, sans-serif;
     -webkit-font-smoothing: antialiased;

Action run for 7e06c98

Copy link

github-actions bot commented Feb 11, 2025

Other changes to npm package

diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.js b/packages/govuk-frontend/dist/govuk/all.bundle.js
index 54140f7f8..b57e1a9a6 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.js
@@ -1756,7 +1756,7 @@
         this.enteredAnotherElement = true;
       });
       document.addEventListener('dragleave', () => {
-        if (!this.enteredAnotherElement) {
+        if (!this.enteredAnotherElement && !this.$button.disabled) {
           this.hideDraggingState();
           this.$announcements.innerText = this.i18n.t('leftDropZone');
         }
@@ -1770,6 +1770,7 @@
      * @param {DragEvent} event - The `dragenter` event
      */
     updateDropzoneVisibility(event) {
+      if (this.$button.disabled) return;
       if (event.target instanceof Node) {
         if (this.$root.contains(event.target)) {
           if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.mjs b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
index ea5e2d5bd..bd59d9bb4 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
@@ -1750,7 +1750,7 @@ class FileUpload extends ConfigurableComponent {
       this.enteredAnotherElement = true;
     });
     document.addEventListener('dragleave', () => {
-      if (!this.enteredAnotherElement) {
+      if (!this.enteredAnotherElement && !this.$button.disabled) {
         this.hideDraggingState();
         this.$announcements.innerText = this.i18n.t('leftDropZone');
       }
@@ -1764,6 +1764,7 @@ class FileUpload extends ConfigurableComponent {
    * @param {DragEvent} event - The `dragenter` event
    */
   updateDropzoneVisibility(event) {
+    if (this.$button.disabled) return;
     if (event.target instanceof Node) {
       if (this.$root.contains(event.target)) {
         if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
diff --git a/packages/govuk-frontend/dist/govuk/components/file-upload/_index.scss b/packages/govuk-frontend/dist/govuk/components/file-upload/_index.scss
index bc63b2e21..08c9705e5 100644
--- a/packages/govuk-frontend/dist/govuk/components/file-upload/_index.scss
+++ b/packages/govuk-frontend/dist/govuk/components/file-upload/_index.scss
@@ -178,6 +178,9 @@
   }
 
   .govuk-file-upload-button--dragging {
+    border-style: solid;
+    border-color: govuk-colour("black");
+
     // extra specificity to apply when
     // empty
     &.govuk-file-upload-button {
@@ -188,18 +191,14 @@
       background-color: govuk-colour("light-grey");
     }
 
-    &:not(:disabled) {
-      border-color: govuk-shade(govuk-colour("mid-grey"), 20%);
-
-      .govuk-file-upload-button__pseudo-button {
-        background-color: govuk-shade(govuk-colour("light-grey"), 10%);
-      }
-    }
-
     &.govuk-file-upload-button--empty:not(:disabled) .govuk-file-upload-button__status,
     &.govuk-file-upload-button--empty .govuk-file-upload-button__pseudo-button {
       background-color: govuk-colour("white");
     }
+
+    .govuk-file-upload-button__pseudo-button {
+      background-color: govuk-shade(govuk-colour("light-grey"), 10%);
+    }
   }
 }
 
diff --git a/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js b/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js
index fcb686c94..6c37a8243 100644
--- a/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.js
@@ -583,7 +583,7 @@
         this.enteredAnotherElement = true;
       });
       document.addEventListener('dragleave', () => {
-        if (!this.enteredAnotherElement) {
+        if (!this.enteredAnotherElement && !this.$button.disabled) {
           this.hideDraggingState();
           this.$announcements.innerText = this.i18n.t('leftDropZone');
         }
@@ -597,6 +597,7 @@
      * @param {DragEvent} event - The `dragenter` event
      */
     updateDropzoneVisibility(event) {
+      if (this.$button.disabled) return;
       if (event.target instanceof Node) {
         if (this.$root.contains(event.target)) {
           if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
diff --git a/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs b/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs
index 102b65489..307cbbd67 100644
--- a/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.bundle.mjs
@@ -577,7 +577,7 @@ class FileUpload extends ConfigurableComponent {
       this.enteredAnotherElement = true;
     });
     document.addEventListener('dragleave', () => {
-      if (!this.enteredAnotherElement) {
+      if (!this.enteredAnotherElement && !this.$button.disabled) {
         this.hideDraggingState();
         this.$announcements.innerText = this.i18n.t('leftDropZone');
       }
@@ -591,6 +591,7 @@ class FileUpload extends ConfigurableComponent {
    * @param {DragEvent} event - The `dragenter` event
    */
   updateDropzoneVisibility(event) {
+    if (this.$button.disabled) return;
     if (event.target instanceof Node) {
       if (this.$root.contains(event.target)) {
         if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
diff --git a/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs b/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs
index c1a28be19..482b1798c 100644
--- a/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs
+++ b/packages/govuk-frontend/dist/govuk/components/file-upload/file-upload.mjs
@@ -98,7 +98,7 @@ class FileUpload extends ConfigurableComponent {
       this.enteredAnotherElement = true;
     });
     document.addEventListener('dragleave', () => {
-      if (!this.enteredAnotherElement) {
+      if (!this.enteredAnotherElement && !this.$button.disabled) {
         this.hideDraggingState();
         this.$announcements.innerText = this.i18n.t('leftDropZone');
       }
@@ -112,6 +112,7 @@ class FileUpload extends ConfigurableComponent {
    * @param {DragEvent} event - The `dragenter` event
    */
   updateDropzoneVisibility(event) {
+    if (this.$button.disabled) return;
     if (event.target instanceof Node) {
       if (this.$root.contains(event.target)) {
         if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {

Action run for 7e06c98

Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

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

Noticed a little issue with the styles changine when dragging over a disabled component, which led to further thinking about the disabled state. If we confirm that the state shouldn't change when disabled, we can expand this PR to do both the black border and the tweaks to disabled styles and screen reader announcements.

@@ -178,6 +178,8 @@
}

.govuk-file-upload-button--dragging {
border-style: solid;
Copy link
Member

Choose a reason for hiding this comment

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

issue This attracted my attention to the fact that the styles change when dragging over a disabled button, while the component won't react to a file being dropped.

Screenshot 2025-02-11 at 16 58 46

@CharlotteDowns thinking it would make sense, when the button is disabled, for it not to react at all visually. Any objection?

@patrickpatrickpatrick if confirmed that we don't want the button to react, it might be easier to check in the JavaScript for the button's disabled property (not attribute, as the button mayb be disabled because it's inside a disabled <fieldset>) before adding .govuk-file-upload-button--dragging, which would avoid us the :not(:disabled) selector. This would also allow us to prevent screen reader announcements as well when the component is disabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

No objection about it not reacting. Once we've made this change are we ready to release?

@patrickpatrickpatrick patrickpatrickpatrick changed the title Add back border to File Upload drop zone Disabled state clean-up Feb 12, 2025
@patrickpatrickpatrick patrickpatrickpatrick changed the title Disabled state clean-up File Upload disabled clean-up Feb 12, 2025
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-5719 February 12, 2025 15:51 Inactive
Copy link
Member

@romaricpascal romaricpascal left a comment

Choose a reason for hiding this comment

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

Dragging styles are fixed, thanks @patrickpatrickpatrick ! @CharlotteDowns I'll make a round on the issue for what's left to do.

Comment on lines +353 to +375
it('does not appear if button disabled', async () => {
await render(page, 'file-upload', examples.enhanced, {
beforeInitialisation() {
document
.querySelector('[type="file"]')
.setAttribute('disabled', '')
}
})

await page.mouse.dragEnter(
{ x: wrapperBoundingBox.x + 1, y: wrapperBoundingBox.y + 1 },
structuredClone(dragData)
)

const disabledAnnouncement = await page.$(
'.govuk-file-upload-announcements'
)

await expect(page.$(selectorDropzoneHidden)).resolves.toBeTruthy()
await expect(
disabledAnnouncement.evaluate((e) => e.textContent)
).resolves.toBe('')
})
Copy link
Member

Choose a reason for hiding this comment

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

🙌🏻

@patrickpatrickpatrick patrickpatrickpatrick merged commit 85e94b6 into spike-enhanced-file-upload Feb 13, 2025
46 checks passed
@patrickpatrickpatrick patrickpatrickpatrick deleted the add-back-border branch February 13, 2025 11:17
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.

4 participants