Fix labels in progress bar percentage selection

We were using the same label for two elements, but the label was only
assigned to one of them.
This commit is contained in:
Javi Martín
2024-10-10 21:30:09 +02:00
parent 233ba3c72f
commit 9f738b8d5f
2 changed files with 25 additions and 2 deletions

View File

@@ -16,12 +16,13 @@
<% end %> <% end %>
</div> </div>
<div class="row"> <div class="row percentage-inputs">
<div class="small-12 medium-6 large-2 column"> <div class="small-12 medium-6 large-2 column">
<%= f.label :percentage %> <%= f.label :percentage, nil, id: "percentage_label" %>
<%= f.text_field :percentage, { type: :range, <%= f.text_field :percentage, { type: :range,
id: "percentage_range", id: "percentage_range",
label: false, label: false,
"aria-labelledby": "percentage_label",
class: "column" }.merge(progress_options) %> class: "column" }.merge(progress_options) %>
</div> </div>

View File

@@ -0,0 +1,22 @@
require "rails_helper"
describe Admin::ProgressBars::FormComponent do
let(:progress_bar) { build(:progress_bar) }
let(:component) { Admin::ProgressBars::FormComponent.new(progress_bar) }
describe "percentage fields" do
it "renders two inputs sharing the same label" do
render_inline component
page.find(".percentage-inputs") do |percentage_inputs|
expect(percentage_inputs).to have_css "input:not([type=submit])", count: 2
expect(percentage_inputs).to have_css "label", count: 1
expect(percentage_inputs).to have_css "label#percentage_label[for=progress_bar_percentage]"
expect(percentage_inputs.all("input")[0][:"aria-labelledby"]).to eq "percentage_label"
expect(percentage_inputs.all("input")[0][:id]).not_to eq "percentage_input"
expect(percentage_inputs.all("input")[1][:id]).to eq "progress_bar_percentage"
end
end
end
end