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 component wrapper in hint component #4214

Merged
merged 1 commit into from
Sep 10, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

## Unreleased

* Use component wrapper in hint component ([PR #4214](https://github.com/alphagov/govuk_publishing_components/pull/4214))
* Hide printed URLs when printing tables ([PR #4209](https://github.com/alphagov/govuk_publishing_components/pull/4209))

## 43.1.0
Expand Down
13 changes: 6 additions & 7 deletions app/views/govuk_publishing_components/components/_hint.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<%
add_gem_component_stylesheet("hint")

id ||= "hint-#{SecureRandom.hex(4)}"
local_assigns[:id] ||= "hint-#{SecureRandom.hex(4)}"
is_radio_label_hint ||= false
right_to_left ||= false
shared_helper = GovukPublishingComponents::Presenters::SharedHelper.new(local_assigns)

css_classes = %w( gem-c-hint govuk-hint )
css_classes << "govuk-radios__hint" if is_radio_label_hint

custom_margin_bottom_class = shared_helper.get_margin_bottom if [*0..9].include?(local_assigns[:margin_bottom])
css_classes << custom_margin_bottom_class if local_assigns[:margin_bottom]
component_helper = GovukPublishingComponents::Presenters::ComponentWrapperHelper.new(local_assigns)
component_helper.add_class("gem-c-hint govuk-hint")
component_helper.add_class("govuk-radios__hint") if is_radio_label_hint
component_helper.add_class(shared_helper.get_margin_bottom) if [*0..9].include?(local_assigns[:margin_bottom])
%>

<%= tag.div id: id, class: css_classes, dir: right_to_left ? "rtl" : nil do %>
<%= tag.div(**component_helper.all_attributes, dir: right_to_left ? "rtl" : nil) do %>
<%= text %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Form hint text
description: Use hints for any form fields.
govuk_frontend_components:
- hint
uses_component_wrapper_helper: true
accessibility_criteria: |
All text must have a contrast ratio higher than 4.5:1 against the background colour to meet [WCAG AA](https://www.w3.org/TR/WCAG20/#visual-audio-contrast-contrast)

Expand Down
18 changes: 18 additions & 0 deletions spec/components/hint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ def component_name
assert_select ".govuk-hint", text: "For example, ‘QQ 12 34 56 C’."
end

it "sets a default id" do
render_component(text: "For example, ‘QQ 12 34 56 C’.")

assert_select ".govuk-hint[id^=hint-]"
end

it "accepts a custom id" do
render_component(text: "For example, ‘QQ 12 34 56 C’.", id: "special-hint")

assert_select ".govuk-hint[id=special-hint]"
end

it "applies a specified bottom margin" do
render_component(text: "For example, ‘QQ 12 34 56 C’.", margin_bottom: 7)

Expand All @@ -29,6 +41,12 @@ def component_name
assert_select '.govuk-hint.govuk-\!-margin-bottom-3', false
end

it "accepts js classes" do
render_component(text: "For example, ‘QQ 12 34 56 C’.", classes: "js-class-one js-class-two")

assert_select ".govuk-hint.js-class-one.js-class-two"
end

it "renders the component with the correct `dir` attribute" do
render_component(
text: "العربيَّة",
Expand Down
Loading