Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use nested hash data attributes in build_data_attributes method #530

Merged
merged 1 commit into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:world@solar.system", class: "govuk-link", lang: "en-GB", dir: "ltr" })
expect(subject).to have_tag("a", text: "hello", with: { href: "mailto:world@solar.system", 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
Loading