diff --git a/lib/govuk_publishing_components/presenters/button_helper.rb b/lib/govuk_publishing_components/presenters/button_helper.rb index bc257e23fa..08dd56af30 100644 --- a/lib/govuk_publishing_components/presenters/button_helper.rb +++ b/lib/govuk_publishing_components/presenters/button_helper.rb @@ -23,7 +23,9 @@ class ButtonHelper :name, :value, :classes, - :aria_label + :aria_label, + :aria_controls, + :aria_describedby def initialize(local_assigns) @href = local_assigns[:href] @@ -52,6 +54,8 @@ def initialize(local_assigns) @aria_label = local_assigns[:aria_label] @info_text_id = "info-text-id-#{SecureRandom.hex(4)}" @button_id = "button-id-#{SecureRandom.hex(4)}" + @aria_controls = local_assigns[:aria_controls] + @aria_describedby = local_assigns[:aria_describedby] end def link? @@ -90,6 +94,8 @@ def html_options options[:name] = name if name.present? && value.present? options[:value] = value if name.present? && value.present? options[:aria] = { label: aria_label } if aria_label + options[:aria][:controls] = aria_controls if aria_controls + options[:aria][:describedby] = aria_describedby if aria_describedby options[:draggable] = false if link? options end diff --git a/spec/components/button_spec.rb b/spec/components/button_spec.rb index f0585948aa..e83c04d462 100644 --- a/spec/components/button_spec.rb +++ b/spec/components/button_spec.rb @@ -231,4 +231,16 @@ def component_name assert_select '.gem-c-button[aria-label="Button with custom label"]' end + + it "renders with aria-controls" do + render_component(text: "Button", aria_controls: "Testing aria-controls") + + assert_select '.gem-c-button[aria-controls="Testing aria-controls"]' + end + + it "renders with aria-describedby" do + render_component(text: "Button", aria_describedby: "Testing aria-describedby") + + assert_select '.gem-c-button[aria-describedby="Testing aria-describedby"]' + end end