Skip to content

Commit 863f114

Browse files
committed
add test and update changelog to show polymorphic slots extend
1 parent d1d1df6 commit 863f114

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

docs/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ nav_order: 6
2222

2323
class SpecialButtonComponent < ButtonComponent
2424
renders_many :leading_items, types: {
25-
svg: SvgComponent,
2625
checkbox: CheckboxComponent
2726
}
2827
end
2928
```
3029

30+
Where `SpecialButtonComponent` will accept `with_leading_item_icon`, `with_leading_item_svg`, and `with_leading_item_checkbox`.
31+
3132
## 4.0.0.rc1
3233

3334
Almost six years after releasing [v1.0.0](https://github.com/ViewComponent/view_component/releases/tag/v1.0.0), we're proud to ship the first release candidate of ViewComponent 4. This release marks a shift towards a Long Term Support model for the project, having reached significant feature maturity. While contributions are always welcome, we're unlikely to accept further breaking changes or major feature additions.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
class PolymorphicSlotSubclassComponent < PolymorphicSlotComponent
4+
renders_one :header, types: {
5+
my: lambda { |&block| content_tag(:div, class: "my", &block) },
6+
}
7+
end

test/sandbox/test/slotable_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,12 @@ def test_component_delegation_slots_work_with_helpers
638638

639639
def test_subclass_can_redefine_slot
640640
render_inline(SlotsSubclassComponent.new(classes: "mt-4")) do |component|
641+
# overridden in subclass
641642
component.with_title do
642643
"This is my title!"
643644
end
645+
646+
# defined in parent class
644647
component.with_subtitle do
645648
"This is my subtitle!"
646649
end
@@ -650,6 +653,21 @@ def test_subclass_can_redefine_slot
650653
assert_selector(".subtitle", text: "This is my subtitle!")
651654
end
652655

656+
def test_subclass_can_redefine_polymorphic_slot_entirely
657+
render_inline(PolymorphicSlotSubclassComponent.new) do |component|
658+
# Overridden in subclass
659+
component.with_header_my { "mine" }
660+
661+
# defined in parent class
662+
component.with_foo_field(class_names: "custom-foo1")
663+
component.with_item_bar(class_names: "custom-bar2")
664+
end
665+
666+
assert_selector("div .my", text: "mine")
667+
assert_selector("div .foo.custom-foo1")
668+
assert_selector("div .bar.custom-bar2")
669+
end
670+
653671
def test_lambda_slot_content_can_be_provided_via_a_block
654672
render_inline LambdaSlotComponent.new do |component|
655673
component.with_header(classes: "some-class") do

0 commit comments

Comments
 (0)