Add proper labels for site customization texts
We were rendering one label and many textarea fields for that label. This meant that, when switching to a different language, the label wasn't correctly associated with the textarea. So we're now rendering one label for each textarea. We could use `aria-label` or `aria-labelledby` instead, but using a label offers some advantages like the fact that clicking on the label makes the textarea take the focus.
This commit is contained in:
@@ -6,7 +6,6 @@
|
|||||||
<% end %>
|
<% end %>
|
||||||
<% contents.each do |group| %>
|
<% contents.each do |group| %>
|
||||||
<% group.each do |content| %>
|
<% group.each do |content| %>
|
||||||
<b><%= content.key %></b>
|
|
||||||
<%= hidden_field_tag "contents[content_#{content.key}][id]", content.key %>
|
<%= hidden_field_tag "contents[content_#{content.key}][id]", content.key %>
|
||||||
<% (content.globalize_locales & enabled_locales.map(&:to_sym)).each do |locale| %>
|
<% (content.globalize_locales & enabled_locales.map(&:to_sym)).each do |locale| %>
|
||||||
<%= render Admin::SiteCustomization::InformationTexts::FormFieldComponent.new(content, locale: locale) %>
|
<%= render Admin::SiteCustomization::InformationTexts::FormFieldComponent.new(content, locale: locale) %>
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
<% globalize(locale) do %>
|
<% globalize(locale) do %>
|
||||||
<%= text_area_tag "contents[content_#{i18n_key}]values[value_#{locale}]",
|
<div class="js-globalize-attribute" data-locale="<%= locale %>" style="<%= display_style %>">
|
||||||
text,
|
<%= label_tag html_id, i18n_key %>
|
||||||
rows: 5,
|
<%= text_area_tag html_name, text, id: html_id, rows: 5 %>
|
||||||
class: "js-globalize-attribute",
|
</div>
|
||||||
style: site_customization_display_translation_style,
|
|
||||||
data: { locale: locale } %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -27,7 +27,15 @@ class Admin::SiteCustomization::InformationTexts::FormFieldComponent < Applicati
|
|||||||
i18n_content.key
|
i18n_content.key
|
||||||
end
|
end
|
||||||
|
|
||||||
def site_customization_display_translation_style
|
def html_id
|
||||||
|
html_name.tr("[", "_").tr("]", "")
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_name
|
||||||
|
"contents[content_#{i18n_key}]values[value_#{locale}]"
|
||||||
|
end
|
||||||
|
|
||||||
|
def display_style
|
||||||
site_customization_enable_translation?(locale) ? "" : "display: none;"
|
site_customization_enable_translation?(locale) ? "" : "display: none;"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -496,11 +496,11 @@ describe "Admin edit translatable records", :admin do
|
|||||||
scenario "Show selected locale form" do
|
scenario "Show selected locale form" do
|
||||||
visit path
|
visit path
|
||||||
|
|
||||||
expect(page).to have_field "contents_content_#{content.key}values_value_en", with: "Value in English"
|
expect(page).to have_field content.key, with: "Value in English"
|
||||||
|
|
||||||
select "Español", from: "Current language"
|
select "Español", from: "Current language"
|
||||||
|
|
||||||
expect(page).to have_field "contents_content_#{content.key}values_value_es", with: "Value en español"
|
expect(page).to have_field content.key, with: "Value en español"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Select a locale and add it to the form" do
|
scenario "Select a locale and add it to the form" do
|
||||||
|
|||||||
Reference in New Issue
Block a user