From d161a624c5e50b7c7605085a50d70d5692f559ec Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 31 Mar 2023 08:49:21 +0200 Subject: [PATCH] a11y(bloc-repetable): ETQ usager qui navigue au clavier, lorsque je supprime une repetition, le focus revient soit sur le premier champ de la derniere repetition, soit sur le bouton ajouter une repetition [si il y a pas de repetition presente] --- .../repetition_component/repetition_component.html.haml | 2 +- app/controllers/champs/repetition_controller.rb | 5 +++-- app/views/champs/repetition/remove.turbo_stream.haml | 5 +++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/components/editable_champ/repetition_component/repetition_component.html.haml b/app/components/editable_champ/repetition_component/repetition_component.html.haml index 392986d3c..f0478483d 100644 --- a/app/components/editable_champ/repetition_component/repetition_component.html.haml +++ b/app/components/editable_champ/repetition_component/repetition_component.html.haml @@ -3,5 +3,5 @@ = render EditableChamp::RepetitionRowComponent.new(form: @form, champ: @champ, row: champs, seen_at: @seen_at) .actions{ 'data-turbo': 'true' } - = button_tag(name: "action", formaction: champs_repetition_path(@champ.id), class: "fr-btn fr-btn--secondary fr-btn--icon-left fr-icon-add-circle-line fr-mb-3w", title: t(".add_title", libelle: @champ.libelle), form: EditableChamp::AddFormRepetitionRowComponent.form_id) do + = button_tag(name: "action", formaction: champs_repetition_path(@champ.id), class: "fr-btn fr-btn--secondary fr-btn--icon-left fr-icon-add-circle-line fr-mb-3w", title: t(".add_title", libelle: @champ.libelle), form: EditableChamp::AddFormRepetitionRowComponent.form_id, id: dom_id(@champ, :create_repetition)) do = t(".add", libelle: @champ.libelle) diff --git a/app/controllers/champs/repetition_controller.rb b/app/controllers/champs/repetition_controller.rb index 25d15c07b..b13979716 100644 --- a/app/controllers/champs/repetition_controller.rb +++ b/app/controllers/champs/repetition_controller.rb @@ -7,8 +7,9 @@ class Champs::RepetitionController < ApplicationController end def remove - champ = policy_scope(Champ).includes(:champs).find(params[:champ_id]) - champ.champs.where(row_id: params[:row_id]).destroy_all + @champ = policy_scope(Champ).includes(:champs).find(params[:champ_id]) + @champ.champs.where(row_id: params[:row_id]).destroy_all + @champ.reload @row_id = params[:row_id] end end diff --git a/app/views/champs/repetition/remove.turbo_stream.haml b/app/views/champs/repetition/remove.turbo_stream.haml index 3e1a66058..5fb0fe0be 100644 --- a/app/views/champs/repetition/remove.turbo_stream.haml +++ b/app/views/champs/repetition/remove.turbo_stream.haml @@ -1 +1,6 @@ = turbo_stream.remove "safe-row-selector-#{@row_id}" + +- if @champ.rows.size > 0 && @champ.rows.last&.first&.present? + = turbo_stream.focus @champ.rows.last&.first.focusable_input_id +- else + = turbo_stream.focus dom_id(@champ, :create_repetition)