Skip to content

Commit

Permalink
Add missing whitelabeling support (#496)
Browse files Browse the repository at this point in the history
Whitelabeling support was missing from `TaskLiskComponent` and the
`visually_hidden` helper.
  • Loading branch information
frankieroberto authored Jan 17, 2024
2 parents 808bdb0 + c9e09f0 commit 9ca69eb
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/components/govuk_component/task_list_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def call
private

def default_attributes
{ class: 'govuk-task-list' }
{ class: "#{brand}-task-list" }
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def status_content
end

def default_attributes
{ class: 'govuk-task-list__item' }
{ class: "#{brand}-task-list__item" }
end

def title_attributes
{ text: raw_title, href:, hint: }
end

def html_attributes_with_link_class
html_attributes.tap { |h| h[:class].append("govuk-task-list__item--with-link") }
html_attributes.tap { |h| h[:class].append("#{brand}-task-list__item--with-link") }
end

def status_attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def render?
def default_attributes
{
class: class_names(
"govuk-task-list__status",
"govuk-task-list__status--cannot-start-yet" => cannot_start_yet,
"#{brand}-task-list__status",
"#{brand}-task-list__status--cannot-start-yet" => cannot_start_yet,
),
id: [id_prefix, count, "status"].compact.join("-"),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def title_content
def hint_content
return if hint.blank?

tag.div(hint, class: "govuk-task-list__hint", id: hint_id)
tag.div(hint, class: "#{brand}-task-list__hint", id: hint_id)
end

def default_attributes
{ class: "govuk-task-list__name-and-hint" }
{ class: "#{brand}-task-list__name-and-hint" }
end

def link_attributes
{ class: "govuk-task-list__link", **aria_described_by_attributes }
{ class: "#{brand}-task-list__link", **aria_described_by_attributes }
end

def aria_described_by_attributes
Expand Down
8 changes: 7 additions & 1 deletion app/helpers/govuk_visually_hidden_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ module GovukVisuallyHiddenHelper
def govuk_visually_hidden(text = nil, &block)
return if text.blank? && block.nil?

tag.span(text, class: "govuk-visually-hidden", &block)
tag.span(text, class: "#{brand}-visually-hidden", &block)
end

private

def brand
Govuk::Components.brand
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,4 +371,5 @@

it_behaves_like 'a component that accepts custom classes'
it_behaves_like 'a component that accepts custom HTML attributes'
it_behaves_like 'a component that supports custom branding'
end
18 changes: 18 additions & 0 deletions spec/helpers/govuk_visually_hidden_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,23 @@

it { is_expected.to have_tag('span', with: { class: "govuk-visually-hidden" }, text: "first item") }
end

context 'when a custom brand is set' do
let(:custom_brand) { 'globex-corp' }

before do
Govuk::Components.configure do |conf|
conf.brand = custom_brand
end
end

after do
Govuk::Components.reset!
end

subject { govuk_visually_hidden("first item") }

it { is_expected.to have_tag('span', with: { class: "#{custom_brand}-visually-hidden" }) }
end
end
end

0 comments on commit 9ca69eb

Please sign in to comment.