Skip to content

Commit bfabd6f

Browse files
committed
Improve input_label/1 component
1 parent 60ac4a3 commit bfabd6f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/backpex/html/layout.ex

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,22 @@ defmodule Backpex.HTML.Layout do
598598
"""
599599
@doc type: :component
600600

601+
attr :as, :string, default: "label", doc: "html tag name"
601602
attr :text, :string, doc: "text of the label"
603+
attr :for, :any, default: nil, doc: "form element the label is bound to"
604+
attr :rest, :global
602605

603606
def input_label(assigns) do
607+
assigns =
608+
case assigns.for do
609+
field = %Phoenix.HTML.FormField{} -> assign(assigns, :rest, Map.put(assigns.rest, :for, field.id))
610+
id -> assign(assigns, :rest, Map.put(assigns.rest, :for, id))
611+
end
612+
604613
~H"""
605-
<p class="text-content block break-words text-sm font-medium">
614+
<.dynamic_tag tag_name={@as} class="text-content block break-words text-sm font-medium" {@rest}>
606615
{@text}
607-
</p>
616+
</.dynamic_tag>
608617
"""
609618
end
610619

0 commit comments

Comments
 (0)