refactor: allow Checkbox and Radio primitives to render headlessly without labels

This commit is contained in:
2026-06-09 20:42:57 +02:00
parent 00758d6a50
commit 7fc29fccb8
2 changed files with 22 additions and 11 deletions
+12 -10
View File
@@ -403,7 +403,7 @@ def Label(
def Checkbox(
name: str,
label: str,
label: str | None = None,
checked: bool = False,
value: str = "1",
attributes: list[HTMLAttribute] | None = None,
@@ -421,20 +421,21 @@ def Checkbox(
if checked:
input_attrs.append(("checked", "true"))
input_el = Input(type="checkbox", attributes=input_attrs)
if label is None:
return input_el
return Label(
attributes=[
("class", "flex items-center gap-2 text-sm text-heading cursor-pointer")
],
children=[
Input(type="checkbox", attributes=input_attrs),
label,
],
children=[input_el, label],
)
def Radio(
name: str,
label: str,
label: str | None = None,
checked: bool = False,
value: str = "",
attributes: list[HTMLAttribute] | None = None,
@@ -452,14 +453,15 @@ def Radio(
if checked:
input_attrs.append(("checked", "true"))
input_el = Input(type="radio", attributes=input_attrs)
if label is None:
return input_el
return Label(
attributes=[
("class", "flex items-center gap-1.5 text-sm text-heading cursor-pointer")
],
children=[
Input(type="radio", attributes=input_attrs),
label,
],
children=[input_el, label],
)