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]

This commit is contained in:
Martin 2023-03-31 08:49:21 +02:00 committed by mfo
parent 8b6a7689fa
commit d161a624c5
3 changed files with 9 additions and 3 deletions

View file

@ -3,5 +3,5 @@
= render EditableChamp::RepetitionRowComponent.new(form: @form, champ: @champ, row: champs, seen_at: @seen_at) = render EditableChamp::RepetitionRowComponent.new(form: @form, champ: @champ, row: champs, seen_at: @seen_at)
.actions{ 'data-turbo': 'true' } .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) = t(".add", libelle: @champ.libelle)

View file

@ -7,8 +7,9 @@ class Champs::RepetitionController < ApplicationController
end end
def remove def remove
champ = policy_scope(Champ).includes(:champs).find(params[:champ_id]) @champ = policy_scope(Champ).includes(:champs).find(params[:champ_id])
champ.champs.where(row_id: params[:row_id]).destroy_all @champ.champs.where(row_id: params[:row_id]).destroy_all
@champ.reload
@row_id = params[:row_id] @row_id = params[:row_id]
end end
end end

View file

@ -1 +1,6 @@
= turbo_stream.remove "safe-row-selector-#{@row_id}" = 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)