Skip to content

Commit d2b3998

Browse files
committed
Pass hint as the content block when rendering
This brings Flowbite::Input::Hint in line with how Flowbite::Input::Label works.
1 parent 9c19ece commit d2b3998

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed

app/components/flowbite/input/hint.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ def styles
2424

2525
def call
2626
tag.p(
27-
@hint,
27+
content,
2828
class: classes,
2929
**@hint_attributes
3030
)
3131
end
3232

33-
def initialize(attribute:, form:, hint:, hint_attributes: {})
33+
def initialize(attribute:, form:, hint_attributes: {})
3434
@attribute = attribute
3535
@form = form
36-
@hint = hint
3736
@hint_attributes = hint_attributes
3837
@object = form.object
3938
end

app/components/flowbite/input_field.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ def input_component
8989
def hint
9090
return unless hint?
9191

92-
render(Flowbite::Input::Hint.new(
92+
component = Flowbite::Input::Hint.new(
9393
attribute: @attribute,
9494
form: @form,
95-
hint: @hint,
9695
hint_attributes: {id: id_for_hint_element}
97-
))
96+
).with_content(@hint)
97+
render(component)
9898
end
9999

100100
protected

app/components/flowbite/input_field/checkbox.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,15 @@ def input_component
1515
def hint
1616
return unless hint?
1717

18-
render(
19-
Flowbite::Input::Hint.new(
20-
attribute: @attribute,
21-
form: @form,
22-
hint_attributes: {
23-
class: hint_classes,
24-
id: id_for_hint_element
25-
},
26-
hint: @hint
27-
)
28-
)
18+
component = Flowbite::Input::Hint.new(
19+
attribute: @attribute,
20+
form: @form,
21+
hint_attributes: {
22+
class: hint_classes,
23+
id: id_for_hint_element
24+
}
25+
).with_content(@hint)
26+
render(component)
2927
end
3028

3129
# Returns the HTML to use for the label element

app/components/flowbite/input_field/radio_button.rb

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,15 @@ def default_label_options
4343
def hint
4444
return unless hint?
4545

46-
render(
47-
Flowbite::Input::Hint.new(
48-
attribute: @attribute,
49-
form: @form,
50-
hint_attributes: {
51-
class: hint_classes,
52-
id: id_for_hint_element
53-
},
54-
hint: @hint
55-
)
56-
)
46+
component = Flowbite::Input::Hint.new(
47+
attribute: @attribute,
48+
form: @form,
49+
hint_attributes: {
50+
class: hint_classes,
51+
id: id_for_hint_element
52+
}
53+
).with_content(@hint)
54+
render(component)
5755
end
5856

5957
private

test/components/input/hint_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ def setup
1212
end
1313

1414
def test_renders_a_hint
15-
render_inline(Flowbite::Input::Hint.new(form: @form, attribute: :title, hint: "What's the title?"))
15+
render_inline(Flowbite::Input::Hint.new(form: @form, attribute: :title)) { "What's the title?" }
1616

1717
assert_component_rendered
1818
assert_selector("p.text-sm.text-gray-500", text: "What's the title?")
1919
end
2020

2121
def test_accepts_custom_attributes
22-
render_inline(Flowbite::Input::Hint.new(form: @form, attribute: :title, hint: "What's the title?", hint_attributes: {id: "custom_hint"}))
22+
render_inline(Flowbite::Input::Hint.new(form: @form, attribute: :title, hint_attributes: {id: "custom_hint"})) { "What's the title?" }
2323

2424
assert_selector("p#custom_hint.text-sm.text-gray-500", text: "What's the title?")
2525
end

0 commit comments

Comments
 (0)