Use coordinates as marker labels when there's only one mappable

When editing/showing a proposal or an investment, the most relevant
information regarding the marker are the coordinates. The title of the
proposal or investment is redundant because we already know the marker
is about that proposal/investment.

There's one problem with this approach, though: when editing a proposal
or an investment, the aria-label of the marker isn't updated
automatically when we move the marker to a different place. This
behaviour will only affect people who use both a screen reader and a
mouse, since keyboard users can't change the position of the marker in
the first place. We'll deal with this issue when we make it possible to
change the position of a marker using the keyboard.
This commit is contained in:
Javi Martín
2025-11-17 04:24:08 +01:00
parent 99696cb302
commit 288f62cdd2
3 changed files with 7 additions and 17 deletions

View File

@@ -62,7 +62,7 @@ class Shared::MapLocationComponent < ApplicationComponent
marker_investments_coordinates: investments_coordinates,
marker_latitude: map_location.latitude.presence,
marker_longitude: map_location.longitude.presence,
marker_title: map_location.title.presence || marker_coordinates_text,
marker_title: marker_coordinates_text,
marker_clustering: feature?("map.feature.marker_clustering"),
geozones: geozones_data
}.merge(input_selectors)

View File

@@ -30,7 +30,7 @@ describe Shared::MapLocationComponent do
end
describe "marker title" do
it "uses the mappable title when there's a mappable with a title" do
it "uses the coordinates when there's a mappable" do
map_location = build(
:map_location,
proposal: Proposal.new(title: "Meet me here"),
@@ -40,7 +40,7 @@ describe Shared::MapLocationComponent do
render_inline Shared::MapLocationComponent.new(map_location)
expect(page).to have_css "[data-marker-title='Meet me here']"
expect(page).to have_css "[data-marker-title='Latitude: 25.25. Longitude: 13.14']"
end
it "uses the coordinates when there's no mappable" do
@@ -51,19 +51,6 @@ describe Shared::MapLocationComponent do
expect(page).to have_css "[data-marker-title='Latitude: 25.25. Longitude: 13.14']"
end
it "uses the coordinates when the mappable has an empty title" do
map_location = build(
:map_location,
proposal: Proposal.new(title: ""),
latitude: "25.25",
longitude: "13.14"
)
render_inline Shared::MapLocationComponent.new(map_location)
expect(page).to have_css "[data-marker-title='Latitude: 25.25. Longitude: 13.14']"
end
it "is not present when the map location isn't available" do
map_location = build(:map_location, latitude: "25.25", longitude: nil)

View File

@@ -175,6 +175,7 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
visit send(mappable_edit_path, id: mappable.id)
expect(page).to have_content "Navigate the map to the location and place the marker."
expect(page).to have_css ".map-icon[aria-label='Latitude: 51.48. Longitude: 0.0']"
expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_latitude", type: :hidden,
with: "51.48"
expect(page).to have_field "#{mappable_factory_name}_map_location_attributes_longitude", type: :hidden,
@@ -255,8 +256,10 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
do_login_for user, management: management if management
visit send(mappable_show_path, arguments)
label = "Latitude: #{map_location.latitude}. Longitude: #{map_location.longitude}"
within ".map-location" do
expect(page).to have_css ".map-icon[aria-label='#{mappable.title}']"
expect(page).to have_css ".map-icon[aria-label='#{label}']"
end
end