Skip to content

Commit 9c9e7f6

Browse files
committed
Allow passing custom options to the hint component
1 parent 3a5eee4 commit 9c9e7f6

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

app/components/flowbite/input_field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def default_hint_options
116116

117117
{
118118
id: id_for_hint_element
119-
}.merge(hint_options || {})
119+
}.merge(hint_options[:options] || {})
120120
end
121121

122122
# Returns a Hash with the default attributes to apply to the input element.

test/components/flowbite/input_field_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def test_adds_aria_attributes_for_hint
2525
assert_selector("p#book_title_hint", text: "What's the title?")
2626
end
2727

28+
def test_adds_extra_attributes_to_hint
29+
render_inline(Flowbite::InputField.new(form: @form, attribute: :title, hint: {content: "What's the title?", options: {class: "custom-hint-class"}}))
30+
31+
assert_selector("p#book_title_hint.custom-hint-class", text: "What's the title?")
32+
end
33+
2834
def test_renders_an_input_element
2935
render_inline(Flowbite::InputField.new(form: @form, attribute: :title))
3036

test/components/input/hint_test.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ def test_renders_a_hint
1818
assert_selector("p.text-sm.text-gray-500", text: "What's the title?")
1919
end
2020

21-
def test_accepts_custom_attributes
21+
def test_accepts_custom_id
2222
render_inline(Flowbite::Input::Hint.new(form: @form, attribute: :title, options: {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
26+
27+
def test_accepts_custom_attributes
28+
render_inline(Flowbite::Input::Hint.new(form: @form, attribute: :title, options: {class: "custom-class"})) { "What's the title?" }
29+
30+
assert_selector("p.custom-class", text: "What's the title?")
31+
end
2632
end

0 commit comments

Comments
 (0)