feat(champ): use new data-turbo-focus-group to manage focus on multiple drop down

This commit is contained in:
Paul Chavard 2023-04-27 09:39:21 +02:00
parent 5343c229a2
commit f9b8dac024
3 changed files with 8 additions and 13 deletions

View file

@ -5,10 +5,11 @@
- b.label(for: @champ.checkbox_id(b.value)) do
- b.check_box({ multiple: true, checked: @champ.selected_options.include?(b.value), aria: { describedby: @champ.describedby_id }, id: @champ.checkbox_id(b.value) }) + b.text
- else
- if @champ.selected_options.present?
.fr-mb-2w{ "data-turbo": "true" }
- @champ.selected_options.each do |option|
= render NestedForms::OwnedButtonComponent.new(formaction: champs_options_path(@champ.id, option:), http_method: :delete, opt: { class: 'fr-tag fr-tag--dismiss fr-mb-1w fr-mr-1w', id: @champ.checkbox_id(option) }) do
= option
- if @champ.unselected_options.present?
= @form.select :value, @champ.unselected_options, { selected: '', include_blank: '' }, id: @champ.input_id, aria: { describedby: @champ.describedby_id }
%div{ 'data-turbo-focus-group': true }
- if @champ.selected_options.present?
.fr-mb-2w{ "data-turbo": "true" }
- @champ.selected_options.each do |option|
= render NestedForms::OwnedButtonComponent.new(formaction: champs_options_path(@champ.id, option:), http_method: :delete, opt: { class: 'fr-tag fr-tag--dismiss fr-mb-1w fr-mr-1w', id: @champ.checkbox_id(option) }) do
= option
- if @champ.unselected_options.present?
= @form.select :value, @champ.unselected_options, { selected: '', include_blank: '' }, id: @champ.input_id, aria: { describedby: @champ.describedby_id }

View file

@ -3,7 +3,6 @@ class Champs::OptionsController < ApplicationController
def remove
@champ = policy_scope(Champ).includes(:champs).find(params[:champ_id])
@next_checkbox_id = @champ.next_checkbox_id(params[:option])
@champ.remove_option([params[:option]].compact)
end
end

View file

@ -1,8 +1,3 @@
= fields_for @champ.input_name, @champ do |form|
= turbo_stream.replace @champ.input_group_id do
= render EditableChamp::EditableChampComponent.new champ: @champ, form:
- if @next_checkbox_id.present?
= turbo_stream.focus @next_checkbox_id
- else
= turbo_stream.focus @champ.input_id