-
Notifications
You must be signed in to change notification settings - Fork 339
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
Update announcement when dropping a file to be the status #5704
Update announcement when dropping a file to be the status #5704
Conversation
📋 StatsFile sizes
Modules
View stats and visualisations on the review app Action run for ddcaa9a |
JavaScript changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
index 69d19059f..7c4de1824 100644
--- a/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
+++ b/packages/govuk-frontend/dist/govuk/govuk-frontend.min.js
@@ -777,10 +777,10 @@ class FileUpload extends ConfigurableComponent {
const c = document.createElement("span");
c.className = "govuk-button govuk-button--secondary govuk-file-upload__pseudo-button", c.innerText = this.i18n.t("chooseFilesButton"), l.appendChild(c), l.insertAdjacentText("beforeend", " ");
const u = document.createElement("span");
- u.className = "govuk-body govuk-file-upload__instruction", u.innerText = this.i18n.t("dropInstruction"), l.appendChild(u), s.appendChild(l), s.setAttribute("aria-labelledby", `${i.id} ${a.id} ${s.id}`), s.addEventListener("click", this.onClick.bind(this)), 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.$input.addEventListener("drop", this.hideDropZone.bind(this)), document.addEventListener("dragenter", this.updateDropzoneVisibility.bind(this)), document.addEventListener("dragenter", (() => {
+ u.className = "govuk-body govuk-file-upload__instruction", u.innerText = this.i18n.t("dropInstruction"), l.appendChild(u), s.appendChild(l), s.setAttribute("aria-labelledby", `${i.id} ${a.id} ${s.id}`), s.addEventListener("click", this.onClick.bind(this)), 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.$input.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.hideDropZone(), this.enteredAnotherElement = !1
+ this.enteredAnotherElement || (this.hideDraggingState(), this.$announcements.innerText = this.i18n.t("leftDropZone")), this.enteredAnotherElement = !1
}))
}
updateDropzoneVisibility(t) {
@@ -788,10 +788,20 @@ class FileUpload extends ConfigurableComponent {
const e = 0 === t.types.length,
n = t.types.some((t => "Files" === t));
return e || n
- }(t.dataTransfer) && (this.$button.classList.contains("govuk-file-upload__button--dragging") || (this.$button.classList.add("govuk-file-upload__button--dragging"), this.$input.classList.add("govuk-file-upload--dragging"), this.$announcements.innerText = this.i18n.t("enteredDropZone"))) : this.$button.classList.contains("govuk-file-upload__button--dragging") && this.hideDropZone())
+ }(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")))
}
- hideDropZone() {
- this.$button.classList.remove("govuk-file-upload__button--dragging"), this.$input.classList.remove("govuk-file-upload--dragging"), this.$announcements.innerText = this.i18n.t("leftDropZone")
+ showDraggingState() {
+ this.$button.classList.add("govuk-file-upload__button--dragging"), this.$input.classList.add("govuk-file-upload--dragging")
+ }
+ hideDraggingState() {
+ this.$button.classList.remove("govuk-file-upload__button--dragging"), this.$input.classList.remove("govuk-file-upload--dragging")
+ }
+ onDrop() {
+ this.hideDraggingState(), this.$input.addEventListener("change", (() => {
+ this.$announcements.innerText = this.$status.innerText
+ }), {
+ once: !0
+ })
}
onChange() {
const t = this.$input.files.length;
@@ -812,7 +822,7 @@ class FileUpload extends ConfigurableComponent {
}
observeDisabledState() {
new MutationObserver((t => {
- for (const e of t) console.log("mutation", e), "attributes" === e.type && "disabled" === e.attributeName && this.updateDisabledState()
+ for (const e of t) "attributes" === e.type && "disabled" === e.attributeName && this.updateDisabledState()
})).observe(this.$input, {
attributes: !0
})
Action run for ddcaa9a |
Other changes to npm packagediff --git a/packages/govuk-frontend/dist/govuk/all.bundle.js b/packages/govuk-frontend/dist/govuk/all.bundle.js
index 9f5123b71..72b727cda 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.js
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.js
@@ -1746,14 +1746,15 @@
this.$announcements.classList.add('govuk-visually-hidden');
this.$announcements.setAttribute('aria-live', 'assertive');
this.$root.insertAdjacentElement('afterend', this.$announcements);
- this.$input.addEventListener('drop', this.hideDropZone.bind(this));
+ this.$input.addEventListener('drop', this.onDrop.bind(this));
document.addEventListener('dragenter', this.updateDropzoneVisibility.bind(this));
document.addEventListener('dragenter', () => {
this.enteredAnotherElement = true;
});
document.addEventListener('dragleave', () => {
if (!this.enteredAnotherElement) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
this.enteredAnotherElement = false;
});
@@ -1769,22 +1770,33 @@
if (this.$root.contains(event.target)) {
if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
if (!this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.$button.classList.add('govuk-file-upload__button--dragging');
- this.$input.classList.add('govuk-file-upload--dragging');
+ this.showDraggingState();
this.$announcements.innerText = this.i18n.t('enteredDropZone');
}
}
} else {
if (this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
}
}
}
- hideDropZone() {
+ showDraggingState() {
+ this.$button.classList.add('govuk-file-upload__button--dragging');
+ this.$input.classList.add('govuk-file-upload--dragging');
+ }
+ hideDraggingState() {
this.$button.classList.remove('govuk-file-upload__button--dragging');
this.$input.classList.remove('govuk-file-upload--dragging');
- this.$announcements.innerText = this.i18n.t('leftDropZone');
+ }
+ onDrop() {
+ this.hideDraggingState();
+ this.$input.addEventListener('change', () => {
+ this.$announcements.innerText = this.$status.innerText;
+ }, {
+ once: true
+ });
}
onChange() {
const fileCount = this.$input.files.length;
@@ -1818,7 +1830,6 @@
observeDisabledState() {
const observer = new MutationObserver(mutationList => {
for (const mutation of mutationList) {
- console.log('mutation', mutation);
if (mutation.type === 'attributes' && mutation.attributeName === 'disabled') {
this.updateDisabledState();
}
diff --git a/packages/govuk-frontend/dist/govuk/all.bundle.mjs b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
index a20682cc7..c6161d0e0 100644
--- a/packages/govuk-frontend/dist/govuk/all.bundle.mjs
+++ b/packages/govuk-frontend/dist/govuk/all.bundle.mjs
@@ -1740,14 +1740,15 @@ class FileUpload extends ConfigurableComponent {
this.$announcements.classList.add('govuk-visually-hidden');
this.$announcements.setAttribute('aria-live', 'assertive');
this.$root.insertAdjacentElement('afterend', this.$announcements);
- this.$input.addEventListener('drop', this.hideDropZone.bind(this));
+ this.$input.addEventListener('drop', this.onDrop.bind(this));
document.addEventListener('dragenter', this.updateDropzoneVisibility.bind(this));
document.addEventListener('dragenter', () => {
this.enteredAnotherElement = true;
});
document.addEventListener('dragleave', () => {
if (!this.enteredAnotherElement) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
this.enteredAnotherElement = false;
});
@@ -1763,22 +1764,33 @@ class FileUpload extends ConfigurableComponent {
if (this.$root.contains(event.target)) {
if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
if (!this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.$button.classList.add('govuk-file-upload__button--dragging');
- this.$input.classList.add('govuk-file-upload--dragging');
+ this.showDraggingState();
this.$announcements.innerText = this.i18n.t('enteredDropZone');
}
}
} else {
if (this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
}
}
}
- hideDropZone() {
+ showDraggingState() {
+ this.$button.classList.add('govuk-file-upload__button--dragging');
+ this.$input.classList.add('govuk-file-upload--dragging');
+ }
+ hideDraggingState() {
this.$button.classList.remove('govuk-file-upload__button--dragging');
this.$input.classList.remove('govuk-file-upload--dragging');
- this.$announcements.innerText = this.i18n.t('leftDropZone');
+ }
+ onDrop() {
+ this.hideDraggingState();
+ this.$input.addEventListener('change', () => {
+ this.$announcements.innerText = this.$status.innerText;
+ }, {
+ once: true
+ });
}
onChange() {
const fileCount = this.$input.files.length;
@@ -1812,7 +1824,6 @@ class FileUpload extends ConfigurableComponent {
observeDisabledState() {
const observer = new MutationObserver(mutationList => {
for (const mutation of mutationList) {
- console.log('mutation', mutation);
if (mutation.type === 'attributes' && mutation.attributeName === 'disabled') {
this.updateDisabledState();
}
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 f547d13aa..b289716a9 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
@@ -573,14 +573,15 @@
this.$announcements.classList.add('govuk-visually-hidden');
this.$announcements.setAttribute('aria-live', 'assertive');
this.$root.insertAdjacentElement('afterend', this.$announcements);
- this.$input.addEventListener('drop', this.hideDropZone.bind(this));
+ this.$input.addEventListener('drop', this.onDrop.bind(this));
document.addEventListener('dragenter', this.updateDropzoneVisibility.bind(this));
document.addEventListener('dragenter', () => {
this.enteredAnotherElement = true;
});
document.addEventListener('dragleave', () => {
if (!this.enteredAnotherElement) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
this.enteredAnotherElement = false;
});
@@ -596,22 +597,33 @@
if (this.$root.contains(event.target)) {
if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
if (!this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.$button.classList.add('govuk-file-upload__button--dragging');
- this.$input.classList.add('govuk-file-upload--dragging');
+ this.showDraggingState();
this.$announcements.innerText = this.i18n.t('enteredDropZone');
}
}
} else {
if (this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
}
}
}
- hideDropZone() {
+ showDraggingState() {
+ this.$button.classList.add('govuk-file-upload__button--dragging');
+ this.$input.classList.add('govuk-file-upload--dragging');
+ }
+ hideDraggingState() {
this.$button.classList.remove('govuk-file-upload__button--dragging');
this.$input.classList.remove('govuk-file-upload--dragging');
- this.$announcements.innerText = this.i18n.t('leftDropZone');
+ }
+ onDrop() {
+ this.hideDraggingState();
+ this.$input.addEventListener('change', () => {
+ this.$announcements.innerText = this.$status.innerText;
+ }, {
+ once: true
+ });
}
onChange() {
const fileCount = this.$input.files.length;
@@ -645,7 +657,6 @@
observeDisabledState() {
const observer = new MutationObserver(mutationList => {
for (const mutation of mutationList) {
- console.log('mutation', mutation);
if (mutation.type === 'attributes' && mutation.attributeName === 'disabled') {
this.updateDisabledState();
}
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 73eef83af..86d3a5ed1 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
@@ -567,14 +567,15 @@ class FileUpload extends ConfigurableComponent {
this.$announcements.classList.add('govuk-visually-hidden');
this.$announcements.setAttribute('aria-live', 'assertive');
this.$root.insertAdjacentElement('afterend', this.$announcements);
- this.$input.addEventListener('drop', this.hideDropZone.bind(this));
+ this.$input.addEventListener('drop', this.onDrop.bind(this));
document.addEventListener('dragenter', this.updateDropzoneVisibility.bind(this));
document.addEventListener('dragenter', () => {
this.enteredAnotherElement = true;
});
document.addEventListener('dragleave', () => {
if (!this.enteredAnotherElement) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
this.enteredAnotherElement = false;
});
@@ -590,22 +591,33 @@ class FileUpload extends ConfigurableComponent {
if (this.$root.contains(event.target)) {
if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
if (!this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.$button.classList.add('govuk-file-upload__button--dragging');
- this.$input.classList.add('govuk-file-upload--dragging');
+ this.showDraggingState();
this.$announcements.innerText = this.i18n.t('enteredDropZone');
}
}
} else {
if (this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
}
}
}
- hideDropZone() {
+ showDraggingState() {
+ this.$button.classList.add('govuk-file-upload__button--dragging');
+ this.$input.classList.add('govuk-file-upload--dragging');
+ }
+ hideDraggingState() {
this.$button.classList.remove('govuk-file-upload__button--dragging');
this.$input.classList.remove('govuk-file-upload--dragging');
- this.$announcements.innerText = this.i18n.t('leftDropZone');
+ }
+ onDrop() {
+ this.hideDraggingState();
+ this.$input.addEventListener('change', () => {
+ this.$announcements.innerText = this.$status.innerText;
+ }, {
+ once: true
+ });
}
onChange() {
const fileCount = this.$input.files.length;
@@ -639,7 +651,6 @@ class FileUpload extends ConfigurableComponent {
observeDisabledState() {
const observer = new MutationObserver(mutationList => {
for (const mutation of mutationList) {
- console.log('mutation', mutation);
if (mutation.type === 'attributes' && mutation.attributeName === 'disabled') {
this.updateDisabledState();
}
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 fc281526c..69ca82332 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
@@ -88,14 +88,15 @@ class FileUpload extends ConfigurableComponent {
this.$announcements.classList.add('govuk-visually-hidden');
this.$announcements.setAttribute('aria-live', 'assertive');
this.$root.insertAdjacentElement('afterend', this.$announcements);
- this.$input.addEventListener('drop', this.hideDropZone.bind(this));
+ this.$input.addEventListener('drop', this.onDrop.bind(this));
document.addEventListener('dragenter', this.updateDropzoneVisibility.bind(this));
document.addEventListener('dragenter', () => {
this.enteredAnotherElement = true;
});
document.addEventListener('dragleave', () => {
if (!this.enteredAnotherElement) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
this.enteredAnotherElement = false;
});
@@ -111,22 +112,33 @@ class FileUpload extends ConfigurableComponent {
if (this.$root.contains(event.target)) {
if (event.dataTransfer && isContainingFiles(event.dataTransfer)) {
if (!this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.$button.classList.add('govuk-file-upload__button--dragging');
- this.$input.classList.add('govuk-file-upload--dragging');
+ this.showDraggingState();
this.$announcements.innerText = this.i18n.t('enteredDropZone');
}
}
} else {
if (this.$button.classList.contains('govuk-file-upload__button--dragging')) {
- this.hideDropZone();
+ this.hideDraggingState();
+ this.$announcements.innerText = this.i18n.t('leftDropZone');
}
}
}
}
- hideDropZone() {
+ showDraggingState() {
+ this.$button.classList.add('govuk-file-upload__button--dragging');
+ this.$input.classList.add('govuk-file-upload--dragging');
+ }
+ hideDraggingState() {
this.$button.classList.remove('govuk-file-upload__button--dragging');
this.$input.classList.remove('govuk-file-upload--dragging');
- this.$announcements.innerText = this.i18n.t('leftDropZone');
+ }
+ onDrop() {
+ this.hideDraggingState();
+ this.$input.addEventListener('change', () => {
+ this.$announcements.innerText = this.$status.innerText;
+ }, {
+ once: true
+ });
}
onChange() {
const fileCount = this.$input.files.length;
@@ -160,7 +172,6 @@ class FileUpload extends ConfigurableComponent {
observeDisabledState() {
const observer = new MutationObserver(mutationList => {
for (const mutation of mutationList) {
- console.log('mutation', mutation);
if (mutation.type === 'attributes' && mutation.attributeName === 'disabled') {
this.updateDisabledState();
}
Action run for ddcaa9a |
Do we still want the console logging for the drag events? |
Oh, definitely not, I forgot to tidy this up, sorry. I'll do that quickly. |
e1bd22f
to
5305535
Compare
5305535
to
ddcaa9a
Compare
@patrickpatrickpatrick I've rebased on the spike branch and removed the |
There was a problem hiding this 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!
Fixes the test for the drop announcement, which seems to not give enough time between the
dragEnter
anddrop
events simulated by Puppeteer for the<input>
to receive the drop.Updates the handling of the user dropping on the component so it announces the status rather than 'Left drop zone'.
Thoughts
Because the
drop
event happens before thechange
event updating the status, a little coordination is necessary.I chose the more compact solution of adding a listener for the next
change
event so there's only one place to update. An alternative could have been the following, but it has many more moving parts (so chances for issues):this.announce
boolean on droponChange
totry { } finally { }
block for safety)The
once
option ofaddEventListener
is available on all browsers that support ES Module, so it's fine to use here.Fixes #5683