Skip to content

Commit 9ecac9b

Browse files
committed
Generate better DOM id when form has no object
Prefer `title_hint` over `_title_hint` for forms without an object
1 parent 3920dda commit 9ecac9b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

app/components/flowbite/input_field.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,13 @@ def hint?
189189
end
190190

191191
def id_for_hint_element
192-
"#{@form.object_name}_#{@attribute}_hint"
192+
[
193+
@form.object_name,
194+
@attribute,
195+
"hint"
196+
]
197+
.compact_blank
198+
.join("_")
193199
end
194200

195201
# @return [Hash] The keyword arguments for the input component.

test/components/flowbite/input_field_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,14 @@ def test_renders_a_hint
175175
def test_adds_aria_attributes_for_hint
176176
render_inline(Flowbite::InputField.new(form: @form, attribute: :title, hint: {content: "What's the title?"}))
177177

178-
assert_selector("input[aria-describedby='_title_hint']")
179-
assert_selector("p#_title_hint", text: "What's the title?")
178+
assert_selector("input[aria-describedby='title_hint']")
179+
assert_selector("p#title_hint", text: "What's the title?")
180180
end
181181

182182
def test_adds_extra_attributes_to_hint
183183
render_inline(Flowbite::InputField.new(form: @form, attribute: :title, hint: {content: "What's the title?", options: {class: "custom-hint-class"}}))
184184

185-
assert_selector("p#_title_hint.custom-hint-class", text: "What's the title?")
185+
assert_selector("p#title_hint.custom-hint-class", text: "What's the title?")
186186
end
187187

188188
def test_renders_an_input_element

0 commit comments

Comments
 (0)