Skip to content

Commit 8da1907

Browse files
committed
Fix when no title is set, have no title.
1 parent 2a3fa92 commit 8da1907

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

lib/petal_components/carousel.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ defmodule PetalComponents.Carousel do
135135
navigate={slide[:navigate]}
136136
href={slide[:href]}
137137
image={slide[:image]}
138-
title={slide[:title] || "Slide #{index + 1}"}
138+
title={slide[:title]}
139139
description={slide[:description]}
140140
/>
141141
</div>
@@ -202,7 +202,7 @@ defmodule PetalComponents.Carousel do
202202
</div>
203203
<div class="pc-carousel__content">
204204
<div class={"pc-carousel__content-wrapper #{@content_position_class}"}>
205-
<div class="pc-carousel__title">
205+
<div :if={!is_nil(@title)} class="pc-carousel__title">
206206
{@title}
207207
</div>
208208
<p :if={!is_nil(@description)} class="pc-carousel__description">

test/petal/carousel_test.exs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,77 @@ defmodule PetalComponents.CarouselTest do
195195
assert slide2_content =~ "href=\"https://github.com/petalframework/petal_components\""
196196
assert slide2_content =~ "class=\"pc-carousel__link\""
197197
end
198+
199+
test "Carousel with content positioning" do
200+
assigns = %{}
201+
202+
html =
203+
rendered_to_string(~H"""
204+
<.carousel id="test-carousel-7" transition_type="fade">
205+
<:slide
206+
content_position="start"
207+
title="Left Aligned Content"
208+
description="This content should be left-aligned"
209+
image="https://example.com/image1.jpg"
210+
/>
211+
<:slide
212+
content_position="center"
213+
title="Center Aligned Content"
214+
description="This content should be centered"
215+
image="https://example.com/image2.jpg"
216+
/>
217+
<:slide
218+
content_position="end"
219+
title="Right Aligned Content"
220+
description="This content should be right-aligned"
221+
image="https://example.com/image3.jpg"
222+
/>
223+
</.carousel>
224+
""")
225+
226+
# Check for proper content position classes
227+
assert html =~ "items-start justify-start text-left"
228+
assert html =~ "items-center justify-center text-center"
229+
assert html =~ "items-end justify-end text-right"
230+
231+
# Verify content is present
232+
assert html =~ "Left Aligned Content"
233+
assert html =~ "Center Aligned Content"
234+
assert html =~ "Right Aligned Content"
235+
end
236+
237+
test "Carousel with slide containing no title" do
238+
assigns = %{}
239+
240+
html =
241+
rendered_to_string(~H"""
242+
<.carousel id="test-carousel-6" transition_type="fade">
243+
<:slide
244+
image="https://example.com/image1.jpg"
245+
description="This slide has a description but no title"
246+
/>
247+
<:slide
248+
image="https://example.com/image2.jpg"
249+
/>
250+
</.carousel>
251+
""")
252+
253+
# Check that image is present
254+
assert html =~ "https://example.com/image1.jpg"
255+
256+
# Check that description is present
257+
assert html =~ "This slide has a description but no title"
258+
259+
# Check that no default title is added (should not have "Slide 1" text)
260+
refute html =~ "Slide 1"
261+
refute html =~ "Slide 2"
262+
263+
# The second slide should only have an image and no text content
264+
slide2_content = html
265+
|> String.split("pc-carousel__slide")
266+
|> Enum.at(2)
267+
268+
assert slide2_content =~ "https://example.com/image2.jpg"
269+
refute slide2_content =~ "pc-carousel__title"
270+
end
198271
end

0 commit comments

Comments
 (0)