Skip to content

Commit bfc081e

Browse files
committed
fix(instruction): open justificatif picker and focus its file input
Clicking "Ajouter un justificatif" hid the button while it held focus. coldwired's hide() moves focus to the previous focusable element, so focus jumped to the motivation textarea. It also only revealed the file input's "Parcourir" button instead of opening the picker. Now the file input is clicked to open the native picker, and focus is sent to it through coldwired's focus action, applied before hide so the button no longer holds focus and hide does not steal it back to motivation.
1 parent f5c9a1a commit bfc081e

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

app/javascript/new_design/instruction-button.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { disable, enable, hide, show } from 'coldwired/actions';
1+
import { disable, dispatchAction, enable, hide, show } from 'coldwired/actions';
22
import { isInputElement } from 'coldwired/utils';
33

44
export function showMotivation(event: Event, state: string) {
@@ -46,6 +46,15 @@ export function deleteJustificatif(name: string) {
4646
}
4747

4848
export function showImportJustificatif(name: string) {
49+
const justificatif = document.querySelector(
50+
`#dossier_justificatif_motivation_${name}`
51+
);
52+
4953
show(`#justificatif_motivation_import_${name}`);
54+
dispatchAction({ action: 'focus', targets: justificatif });
5055
hide(`#justificatif_motivation_suggest_${name}`);
56+
57+
if (isInputElement(justificatif)) {
58+
justificatif.click();
59+
}
5160
}

spec/system/instructeurs/instruction_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@
128128
expect(dossier.reload.state).to eq(Dossier.states.fetch(:refuse))
129129
end
130130

131+
scenario 'moves focus to the justificatif file input when adding a justificatif' do
132+
dossier.passer_en_instruction!(instructeur: instructeur)
133+
login_as(instructeur.user, scope: :user)
134+
135+
visit instructeur_dossier_path(procedure, dossier)
136+
click_on 'Rendre une décision'
137+
138+
within('.instruction-button') { find_link('Refuser').click }
139+
expect(page).to have_field('motivation_refuse')
140+
141+
within('.refuse.motivation') { click_on 'Ajouter un justificatif' }
142+
143+
expect(page).to have_css('#dossier_justificatif_motivation_refuse:focus')
144+
expect(page).to have_no_css('#motivation_refuse:focus')
145+
end
146+
131147
scenario 'A instructeur can follow/unfollow a dossier and request an export' do
132148
login_as(instructeur.user, scope: :user)
133149
visit instructeur_procedures_path

0 commit comments

Comments
 (0)