Skip to content

Commit

Permalink
Merge pull request #363 from petalframework/radio-card
Browse files Browse the repository at this point in the history
Radio card extra
  • Loading branch information
mitkins authored Oct 28, 2024
2 parents f433011 + 8048179 commit 37a2c1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/petal_components/field.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule PetalComponents.Field do
attr :size, :string,
default: "md",
values: ~w(xs sm md lg xl),
doc: "the size of the switch or radio card"
doc: "the size of the switch (xs, sm, md, lg or xl) or radio card (sm, md or lg)"

attr :variant, :any, default: "outline", doc: "outline, classic - used by radio-card"

Expand Down Expand Up @@ -321,7 +321,6 @@ defmodule PetalComponents.Field do
assigns =
assigns
|> assign_new(:checked, fn -> nil end)
|> assign_new(:class, fn -> "" end)
|> assign_new(:options, fn -> [] end)
|> assign_new(:group_layout, fn -> "row" end)
|> assign_new(:id_prefix, fn -> assigns.id || assigns.name || "radio_card" end)
Expand Down
13 changes: 13 additions & 0 deletions test/petal/field_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,19 @@ defmodule PetalComponents.FieldTest do
assert html =~ "custom-class"
end

test "field radio-card group_layout attr" do
assigns = %{form: to_form(%{}, as: :user)}

html =
rendered_to_string(~H"""
<.form for={@form}>
<.field type="radio-card" field={@form[:plans]} />
</.form>
""")

assert html =~ "pc-radio-card-group--row"
end

test "field radio-card checked on form field" do
assigns = %{form: to_form(%{"plans" => "pro"}, as: :user)}

Expand Down

0 comments on commit 37a2c1e

Please sign in to comment.