Skip to content

Commit

Permalink
Use nested data attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBiddle committed Apr 5, 2024
1 parent 9ad62cf commit d72a810
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
8 changes: 5 additions & 3 deletions app/helpers/govuk_link_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ def controller_warning_message(value)

def build_data_attributes(data_module, prevent_double_click: nil)
{
"data-module": data_module,
"data-prevent-double-click": prevent_double_click
}.compact
data: {
module: data_module,
"prevent-double-click": prevent_double_click
}.compact
}
end
end

Expand Down
15 changes: 8 additions & 7 deletions spec/helpers/govuk_link_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ def url_for(path)
end

context "when there are custom attributes" do
let(:kwargs) { { lang: "en-GB", dir: "ltr" } }
let(:kwargs) { { lang: "en-GB", dir: "ltr", data: { module: "custom-module" } } }

specify "the custom attributes are present on the link" do
expect(subject).to have_tag("a", text: "hello", with: { href: "/world", class: "govuk-link", lang: "en-GB", dir: "ltr" })
expect(subject).to have_tag("a", text: "hello", with: { href: "/world", class: "govuk-link", lang: "en-GB", dir: "ltr", "data-module": "custom-module" })
end
end

Expand Down Expand Up @@ -314,10 +314,10 @@ def url_for(path)
end

context "when there are custom attributes" do
let(:kwargs) { { lang: "en-GB", dir: "ltr" } }
let(:kwargs) { { lang: "en-GB", dir: "ltr", data: { module: "custom-module" } } }

specify "the custom attributes are present on the link" do
expect(subject).to have_tag("a", text: "hello", with: { href: "mailto:[email protected]", class: "govuk-link", lang: "en-GB", dir: "ltr" })
expect(subject).to have_tag("a", text: "hello", with: { href: "mailto:[email protected]", class: "govuk-link", lang: "en-GB", dir: "ltr", "data-module": "custom-module" })
end
end
end
Expand Down Expand Up @@ -502,10 +502,10 @@ def url_for(path)
end

context "when there are custom attributes" do
let(:kwargs) { { lang: "en-GB", dir: "ltr" } }
let(:kwargs) { { lang: "en-GB", dir: "ltr", data: { module: "custom-module" } } }

specify "the custom attributes are present on the link" do
expect(subject).to have_tag("a", text: "hello", with: { href: "/world", class: "govuk-button", lang: "en-GB", dir: "ltr" })
expect(subject).to have_tag("a", text: "hello", with: { href: "/world", class: "govuk-button", lang: "en-GB", dir: "ltr", "data-module": "custom-module" })
end
end
end
Expand Down Expand Up @@ -661,7 +661,7 @@ def url_for(path)
end

context "when there are custom attributes" do
let(:kwargs) { { lang: "en-GB", dir: "ltr" } }
let(:kwargs) { { lang: "en-GB", dir: "ltr", data: { module: "custom-module" } } }

specify "the custom attributes are present on the button" do
expect(subject).to have_tag("form", with: { method: "post", action: "/world" }) do
Expand All @@ -672,6 +672,7 @@ def url_for(path)
class: %w[govuk-button],
dir: "ltr",
lang: "en-GB",
"data-module": "custom-module"
}
)
end
Expand Down

0 comments on commit d72a810

Please sign in to comment.