Skip to content

Commit 576b816

Browse files
authored
Merge pull request #1570 from naymspace/feature/use-description-list
Use description list in `field_container/1`
2 parents 0a0c752 + b7a4aaa commit 576b816

File tree

6 files changed

+40
-16
lines changed

6 files changed

+40
-16
lines changed

demo/test/demo_web/live/category_live_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ defmodule DemoWeb.Live.CategoryLiveTest do
5252
conn
5353
|> visit(~p"/admin/categories/#{category.id}/show")
5454
|> assert_has("h1", text: "Category", exact: true)
55-
|> assert_has("p", text: "Name", exact: true)
56-
|> assert_has("p", text: category.name, exact: true)
55+
|> assert_has("dt", text: "Name", exact: true)
56+
|> assert_has("dd", text: category.name, exact: true)
5757
end
5858
end
5959

demo/test/demo_web/live/tag_live_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ defmodule DemoWeb.Live.TagLiveTest do
5252
conn
5353
|> visit(~p"/admin/tags/#{tag.id}/show")
5454
|> assert_has("h1", text: "Tag", exact: true)
55-
|> assert_has("p", text: "Name", exact: true)
56-
|> assert_has("p", text: "Inserted At", exact: true)
57-
|> assert_has("p", text: tag.name, exact: true)
55+
|> assert_has("dt", text: "Name", exact: true)
56+
|> assert_has("dt", text: "Inserted At", exact: true)
57+
|> assert_has("dd", text: tag.name, exact: true)
5858
end
5959
end
6060

demo/test/demo_web/live/ticket_live_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ defmodule DemoWeb.TicketLiveTest do
3535
conn
3636
|> visit(~p"/admin/tickets/#{ticket.id}/show")
3737
|> assert_has("h1", text: "Ticket", exact: true)
38-
|> assert_has("p", text: "Subject", exact: true)
39-
|> assert_has("p", text: "Body", exact: true)
40-
|> assert_has("p", text: ticket.subject, exact: true)
41-
|> assert_has("p", text: ticket.body, exact: true)
38+
|> assert_has("dt", text: "Subject", exact: true)
39+
|> assert_has("dt", text: "Body", exact: true)
40+
|> assert_has("dd", text: ticket.subject, exact: true)
41+
|> assert_has("dd", text: ticket.body, exact: true)
4242
end
4343
end
4444
end

guides/upgrading/v0.16.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Upgrading to v0.16
2+
3+
## Bump Your Deps
4+
5+
Update Backpex to the latest version:
6+
7+
```elixir
8+
defp deps do
9+
[
10+
{:backpex, "~> 0.16.0"}
11+
]
12+
end
13+
```
14+
15+
## Component changes
16+
17+
- `Backpex.HTML.Layout.field_container/1` now uses a `dl` element instead of a `div` element to better align with HTML semantics.

lib/backpex/html/layout.ex

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ defmodule Backpex.HTML.Layout do
500500
"""
501501
@doc type: :component
502502

503-
attr :class, :string, default: "", doc: "extra classes to be added"
503+
attr :class, :any, default: nil, doc: "extra classes to be added"
504504

505505
slot :label, required: true do
506506
attr :align, :atom, values: [:top, :center, :bottom]
@@ -509,16 +509,22 @@ defmodule Backpex.HTML.Layout do
509509
slot :inner_block
510510

511511
def field_container(assigns) do
512+
assigns =
513+
update(assigns, :label, fn
514+
[label] -> label
515+
_other -> raise ArgumentError, "Expected a single label slot, got: #{inspect(assigns.label)}"
516+
end)
517+
512518
~H"""
513-
<div class={"#{@class} flex flex-col items-stretch space-y-2 px-6 py-4 sm:flex-row sm:space-y-0 sm:py-3"}>
514-
<div :for={label <- @label} class={"#{get_align_class(label[:align])} hyphens-auto break-words pr-2 sm:w-1/4"}>
519+
<dl class={["flex flex-col items-stretch space-y-2 px-6 py-4 sm:flex-row sm:space-y-0 sm:py-3", @class]}>
520+
<dt class={["hyphens-auto break-words pr-2 sm:w-1/4", get_align_class(@label[:align])]}>
515521
{render_slot(@label)}
516-
</div>
522+
</dt>
517523
518-
<div class="w-full sm:w-3/4">
524+
<dd class="w-full sm:w-3/4">
519525
{render_slot(@inner_block)}
520-
</div>
521-
</div>
526+
</dd>
527+
</dl>
522528
"""
523529
end
524530

mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ defmodule Backpex.MixProject do
195195
"guides/translations/translations.md",
196196

197197
# Upgrade Guides
198+
"guides/upgrading/v0.16.md",
198199
"guides/upgrading/v0.15.md",
199200
"guides/upgrading/v0.14.md",
200201
"guides/upgrading/v0.13.md",

0 commit comments

Comments
 (0)