From df3bd3a1d207ff7da7bb8a751007d49a739c3104 Mon Sep 17 00:00:00 2001 From: Christophe Robillard Date: Tue, 9 Mar 2021 18:56:57 +0100 Subject: [PATCH] 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}\"]") %>