Skip to content

Commit ccf3f28

Browse files
committed
Streamline RadioButton hint API
The API of Flowbite::InputField::RadioButton should follow the same structure as the other components for hints. Instead of passing a String `hint: "This is the hint" you now have to pass a Hash that's passed along to the Hint component hint: {content: "This is the hint"} . This allows consumers to customize other options (eg HTML attributes like class) in addition to the hint text.
1 parent 7ee7fbf commit ccf3f28

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
1313

1414
### Changed
1515

16+
* [BREAKING] The API of Flowbite::InputField::RadioButton now follows the same structure as the other components for hints.Instead of passing a String (`hint: "This is the hint"`) you now have to pass a Hash that's passed along to the Hint component (ie `hint: {content: "This is the hint"}`), allowing you to customize other options (eg HTML attributes like class) as well.
17+
1618
### Removed
1719

1820

app/components/flowbite/input_field/radio_button.rb

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ def default_input
2626
input_component.new(**args)
2727
end
2828

29+
def default_hint_options
30+
return {} unless @hint
31+
32+
{
33+
class: hint_classes,
34+
id: id_for_hint_element
35+
}.merge(@hint[:options] || {})
36+
end
37+
2938
# Returns options for the default label element. This includes CSS classes
3039
# since they are specific to RadioButton labels (and Checkbox ones).
3140
def default_label_options
@@ -37,21 +46,6 @@ def default_label_options
3746
})
3847
end
3948

40-
# Returns the HTML to use for the hint element if any
41-
def hint
42-
return unless hint?
43-
44-
component = Flowbite::Input::Hint.new(
45-
attribute: @attribute,
46-
form: @form,
47-
options: {
48-
class: hint_classes,
49-
id: id_for_hint_element
50-
}
51-
).with_content(@hint)
52-
render(component)
53-
end
54-
5549
def input_component
5650
::Flowbite::Input::RadioButton
5751
end

test/components/input_field/radio_button_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,13 @@ def test_renders_unchecked_when_false
4545
end
4646

4747
def test_renders_a_hint
48-
render_inline(Flowbite::InputField::RadioButton.new(form: @form, attribute: :state, value: "visible", hint: "Profile can be accessed publicly"))
48+
render_inline(Flowbite::InputField::RadioButton.new(form: @form, attribute: :state, value: "visible", hint: {content: "Profile can be accessed publicly"}))
4949

5050
assert_selector("p.text-xs.font-normal.text-body", text: "Profile can be accessed publicly")
5151
end
5252

5353
def test_adds_aria_attributes_for_hint
54-
render_inline(Flowbite::InputField::RadioButton.new(form: @form, attribute: :state, hint: "Profile can be accessed publicly", value: "visible"))
54+
render_inline(Flowbite::InputField::RadioButton.new(form: @form, attribute: :state, hint: {content: "Profile can be accessed publicly"}, value: "visible"))
5555

5656
assert_selector("input[aria-describedby='article_state_visible_hint']")
5757
assert_selector("p#article_state_visible_hint", text: "Profile can be accessed publicly")

0 commit comments

Comments
 (0)