From 43039d1755348e4688f3990ff2e98f1b29585a8a Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Mon, 8 Mar 2021 17:09:44 +0100 Subject: [PATCH 1/4] add aria-value min, max and now for progressbar upload --- app/javascript/shared/activestorage/progress-bar.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/javascript/shared/activestorage/progress-bar.js b/app/javascript/shared/activestorage/progress-bar.js index fbc3797a9..396bf61a7 100644 --- a/app/javascript/shared/activestorage/progress-bar.js +++ b/app/javascript/shared/activestorage/progress-bar.js @@ -32,6 +32,7 @@ export default class ProgressBar { const element = getDirectUploadProgressElement(id); if (element) { element.style.width = `${progress}%`; + element.setAttribute('aria-valuenow', progress); } } @@ -52,7 +53,7 @@ export default class ProgressBar { static render(id, filename) { return `
-
+
${filename}
`; } From df3bd3a1d207ff7da7bb8a751007d49a739c3104 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 9 Mar 2021 18:56:57 +0100 Subject: [PATCH 2/4] handle focus during and after upload --- app/helpers/application_helper.rb | 6 ++++++ app/javascript/shared/activestorage/progress-bar.js | 1 + app/views/champs/piece_justificative/show.js.erb | 2 ++ 3 files changed, 9 insertions(+) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 443d7c166..90fde6aa2 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -79,6 +79,12 @@ module ApplicationHelper # rubocop:enable Rails/OutputSafety end + def focus_element(selector) + # rubocop:disable Rails/OutputSafety + raw("document.querySelector('#{selector}').focus();") + # rubocop:enable Rails/OutputSafety + end + def disable_element(selector) # rubocop:disable Rails/OutputSafety raw("document.querySelector('#{selector}').disabled = true;") diff --git a/app/javascript/shared/activestorage/progress-bar.js b/app/javascript/shared/activestorage/progress-bar.js index 396bf61a7..5c9d6625c 100644 --- a/app/javascript/shared/activestorage/progress-bar.js +++ b/app/javascript/shared/activestorage/progress-bar.js @@ -25,6 +25,7 @@ export default class ProgressBar { const element = getDirectUploadElement(id); if (element) { element.classList.remove(PENDING_CLASS); + element.focus(); } } diff --git a/app/views/champs/piece_justificative/show.js.erb b/app/views/champs/piece_justificative/show.js.erb index 80b454204..c8bbaf377 100644 --- a/app/views/champs/piece_justificative/show.js.erb +++ b/app/views/champs/piece_justificative/show.js.erb @@ -4,3 +4,5 @@ <% if attachment.virus_scanner.pending? %> <%= fire_event('attachment:update', { url: attachment_url(attachment.id, { signed_id: attachment.blob.signed_id, user_can_upload: true }) }.to_json ) %> <% end %> + +<%= focus_element("button[data-toggle-target=\".attachment-input-#{attachment.id}\"]") %> From 6026793c1d5dd2851c416ec6a2c25f2bf3d47708 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 16 Mar 2021 11:33:39 +0100 Subject: [PATCH 3/4] focus to target after toggle --- app/javascript/shared/toggle-target.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/javascript/shared/toggle-target.js b/app/javascript/shared/toggle-target.js index 945c379e1..508492a8e 100644 --- a/app/javascript/shared/toggle-target.js +++ b/app/javascript/shared/toggle-target.js @@ -16,5 +16,6 @@ delegate('click', TOGGLE_SOURCE_SELECTOR, (evt) => { const targetElements = document.querySelectorAll(targetSelector); for (let target of targetElements) { toggle(target); + target.focus(); } }); From f47e2e62cdb2d2c1c5b01ccc837f39429749c913 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 16 Mar 2021 15:11:54 +0100 Subject: [PATCH 4/4] add button role to supprimer link --- app/views/shared/attachment/_edit.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/shared/attachment/_edit.html.haml b/app/views/shared/attachment/_edit.html.haml index 79910db79..54ec64236 100644 --- a/app/views/shared/attachment/_edit.html.haml +++ b/app/views/shared/attachment/_edit.html.haml @@ -19,7 +19,7 @@ = render partial: "shared/attachment/show", locals: { attachment: attachment, user_can_upload: true } - if user_can_destroy .attachment-action - = link_to 'Supprimer', attachment_url(attachment.id, { signed_id: attachment.blob.signed_id }), remote: true, method: :delete, class: 'button small danger', data: { disable: true } + = link_to 'Supprimer', attachment_url(attachment.id, { signed_id: attachment.blob.signed_id }), remote: true, method: :delete, class: 'button small danger', data: { disable: true }, role: 'button' .attachment-action = button_tag 'Remplacer', type: 'button', class: 'button small', data: { 'toggle-target': ".attachment-input-#{attachment_id}" }