Use heading name as link text

Using the name instead of using the name and the price is IMHO more
consistent with the rest of the application, particularly for screen
reader users. Writing texts clicking those links is also easier.

I think the main reason why we used the price as part of the link was so
the clickable area was bigger. We can accomplish the same result with
CSS.
This commit is contained in:
Javi Martín
2021-03-15 23:59:18 +01:00
parent f1b707f549
commit 4c23f639be
5 changed files with 38 additions and 27 deletions

View File

@@ -13,6 +13,8 @@
border-radius: rem-calc(3);
margin-bottom: $line-height / 2;
margin-left: $spacing;
padding: $line-height / 2;
position: relative;
width: 100%;
@include breakpoint(medium) {
@@ -23,22 +25,37 @@
width: calc(100% / 6 - #{$spacing});
}
&:focus-within {
outline: $outline-focus;
a:focus {
outline: none;
}
}
a {
display: block;
padding: $line-height / 2;
&::after,
&::before {
bottom: 0;
content: "";
left: 0;
position: absolute;
right: 0;
top: 0;
}
&:hover {
background: $highlight;
text-decoration: none;
}
}
.heading-name {
padding: $line-height / 2;
&:hover::before {
background: $highlight;
z-index: -1;
}
}
span {
color: $text;
display: block;
font-size: $small-font-size;
}

View File

@@ -4,16 +4,13 @@
<ul class="headings-list">
<% group.headings.sort_by_name.each do |heading| %>
<li class="heading">
<% unless budget.informing? || budget.finished? %>
<%= link_to budget_investments_path(budget.id,
heading_id: heading.id) do %>
<%= heading_name_and_price_html(heading) %>
<% end %>
<% else %>
<div class="heading-name">
<%= heading_name_and_price_html(heading) %>
</div>
<% end %>
<%= link_to_unless(
(budget.informing? || budget.finished?),
heading.name,
budget_investments_path(budget.id, heading_id: heading.id)
) %>
<%= price(heading) %>
</li>
<% end %>
</ul>

View File

@@ -7,10 +7,7 @@ class Budgets::GroupsAndHeadingsComponent < ApplicationComponent
private
def heading_name_and_price_html(heading)
tag.div do
concat(heading.name + " ")
concat(tag.span(budget.formatted_heading_price(heading)))
end
def price(heading)
tag.span(budget.formatted_heading_price(heading))
end
end

View File

@@ -118,7 +118,7 @@ describe "Budgets" do
visit budgets_path
within("#budget_info") do
expect(page).not_to have_link "#{heading.name} €1,000,000"
expect(page).not_to have_link heading.name
expect(page).to have_content "#{heading.name} €1,000,000"
expect(page).not_to have_link("List of all investment projects")
@@ -136,7 +136,7 @@ describe "Budgets" do
visit budgets_path
within("#budget_info") do
expect(page).not_to have_link "#{heading.name} €1,000,000"
expect(page).not_to have_link heading.name
expect(page).to have_content "#{heading.name} €1,000,000"
expect(page).to have_css("div.map")

View File

@@ -1230,7 +1230,7 @@ describe "Budget Investments" do
first(:link, "Participatory budgeting").click
click_link "More hospitals €666,666"
click_link "More hospitals"
within("#budget_investment_#{investment1.id}") do
expect(page).to have_content investment1.title