Skip to content

Commit b203356

Browse files
committed
make alt text for form logo configurable
1 parent aa2f92b commit b203356

11 files changed

Lines changed: 64 additions & 7 deletions

File tree

app/controllers/admin/forms_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ def form_params
518518
:notification_frequency,
519519
:logo,
520520
:header_logo_display,
521+
:logo_alt_text,
521522
:modal_button_text,
522523
:success_text_heading,
523524
:success_text,
@@ -561,7 +562,7 @@ def form_params
561562

562563
def form_logo_params
563564
params.require(:form).permit(
564-
:logo, :header_logo_display
565+
:logo, :header_logo_display, :logo_alt_text
565566
)
566567
end
567568

app/models/form.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class Form < ApplicationRecord
4242

4343
enum :header_logo_display, { banner: 'banner', square: 'square' }, default: 'banner', prefix: true
4444

45+
def logo_alt_text_or_default
46+
return logo_alt_text if logo_alt_text.present?
47+
48+
"#{organization&.name} logo"
49+
end
50+
4551
def self.my_forms(user, aasm_state)
4652
if user.organizational_form_approver?
4753
items = user.organization.forms
@@ -340,6 +346,7 @@ def touchpoints_js_string
340346
'form-header-logo-square'
341347
end
342348
end,
349+
logo_alt_text: (logo_alt_text_or_default if logo.present?),
343350
questions: ordered_questions.map do |q|
344351
{
345352
answer_field: q.answer_field,

app/serializers/form_serializer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class FormSerializer < ActiveModel::Serializer
2323
:whitelist_url_9,
2424
:whitelist_test_url,
2525
:header_logo_display,
26+
:logo_alt_text,
2627
:success_text_heading,
2728
:success_text,
2829
:modal_button_text,

app/serializers/full_form_serializer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def links
4545
:whitelist_url_9,
4646
:whitelist_test_url,
4747
:header_logo_display,
48+
:logo_alt_text,
4849
:success_text_heading,
4950
:success_text,
5051
:modal_button_text,

app/views/admin/forms/_logo_display.html.erb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
<div class="usa-form-group">
2323
<div class="usa-label text-uppercase font-body-3xs">Current logo</div>
2424
<%- if form.header_logo_display_banner? %>
25-
<%= image_tag(form.logo.tag.url, alt: "#{form.organization.name} logo", class: "form-header-logo") %>
25+
<%= image_tag(form.logo.tag.url, alt: form.logo_alt_text_or_default, class: "form-header-logo") %>
2626
<%- elsif form.header_logo_display_square? %>
27-
<%= image_tag(form.logo.logo_square.url, alt: "#{form.organization.name} logo", class: "form-header-logo-square") %>
27+
<%= image_tag(form.logo.logo_square.url, alt: form.logo_alt_text_or_default, class: "form-header-logo-square") %>
2828
<%- end %>
2929
</div>
3030
<% end %>
@@ -44,6 +44,17 @@
4444
<%= f.label :header_logo_display, "Display as square (80px wide by 80px tall)", class: "usa-radio__label", value: "square" %>
4545
</div>
4646
</fieldset>
47+
<div class="usa-form-group margin-top-2">
48+
<%= f.label :logo_alt_text, "Logo alt text", class: "usa-label text-uppercase font-body-3xs" %>
49+
<span class="usa-hint text-base-dark" id="logo-alt-text-hint">
50+
Describe the logo for people using screen readers.
51+
Leave blank to use "<%= form.organization&.name %> logo".
52+
</span>
53+
<%= f.text_field :logo_alt_text,
54+
value: form.logo_alt_text,
55+
class: "usa-input",
56+
aria_describedby: "logo-alt-text-hint" %>
57+
</div>
4758
<div class="margin-top-1">
4859
<%= f.submit "Update Logo Display", class: "usa-button usa-button-outline" %>
4960
<%- if form.logo.present? %>

app/views/components/forms/_logo_and_title.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
<div class="margin-bottom-2 text-center">
77
<%- if form.header_logo_display_banner? %>
88
<%= image_tag(form.logo.tag.url,
9-
alt: "#{form.organization.name} banner",
9+
alt: form.logo_alt_text_or_default,
1010
class: "form-header-logo") %>
1111
<% elsif form.header_logo_display_square? %>
1212
<%= image_tag(form.logo.logo_square.url,
13-
alt: "#{form.organization.name} logo",
13+
alt: form.logo_alt_text_or_default,
1414
class: "form-header-logo-square") %>
1515
<% end %>
1616
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class AddLogoAltTextToForms < ActiveRecord::Migration[8.1]
4+
def change
5+
add_column :forms, :logo_alt_text, :string
6+
end
7+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[8.1].define(version: 2026_06_01_125209) do
13+
ActiveRecord::Schema[8.1].define(version: 2026_06_18_210000) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_catalog.plpgsql"
1616

@@ -267,6 +267,7 @@
267267
t.string "legacy_touchpoint_uuid"
268268
t.boolean "load_css", default: true
269269
t.string "logo"
270+
t.string "logo_alt_text"
270271
t.string "medium"
271272
t.string "modal_button_text"
272273
t.string "name"

db/seeds.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def production_suitable_seeds
8585

8686
org_2 = Organization.create!({
8787
name: 'Farmers.gov',
88-
domain: 'example.gov',
88+
domain: 'farmers.gov',
8989
url: 'https://farmers.gov',
9090
abbreviation: 'FARMERS'
9191
})

spec/controllers/admin/forms_controller_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,18 @@
309309
expect(form.header_logo_display).to eq('banner')
310310
expect(response).to render_template(:update_display_logo)
311311
end
312+
313+
it 'updates the logo alt text' do
314+
patch :update_display_logo, params: {
315+
id: form.to_param,
316+
form: { logo: logo_file, header_logo_display: 'banner', logo_alt_text: 'Agency seal' },
317+
format: :js
318+
}, session: valid_session
319+
320+
form.reload
321+
expect(form.logo_alt_text).to eq('Agency seal')
322+
expect(response).to render_template(:update_display_logo)
323+
end
312324
end
313325

314326
context 'with invalid file type' do

0 commit comments

Comments
 (0)