handle focus during and after upload

This commit is contained in:
Christophe Robillard 2021-03-09 18:56:57 +01:00
parent 43039d1755
commit df3bd3a1d2
3 changed files with 9 additions and 0 deletions

View file

@ -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;")

View file

@ -25,6 +25,7 @@ export default class ProgressBar {
const element = getDirectUploadElement(id);
if (element) {
element.classList.remove(PENDING_CLASS);
element.focus();
}
}

View file

@ -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}\"]") %>