Label is used to provide a name or title for an input field. Label can be placed before or after the field.
Base Label
Exported source
label = SingleValueFactory("label", "Base label component for styling the text next to an input field (or select)") # Base label componentfloating_label = SingleValueFactory("floating-label", "Floating label component for the parent of an input field (or select) and a span that floats above the input field when the field is focused") # Base floating label component
Label Test Examples
test_label_basic_examples
def test_label_basic_examples():
Test basic label utilities.
Exported source
def test_label_basic_examples():"""Test basic label utilities."""# Basic labelassertstr(label) =="label"assertstr(floating_label) =="floating-label"# Test with modifiersassertstr(label.hover) =="hover:label"assertstr(label.md) =="md:label"assertstr(label.dark) =="dark:label"# Test with modifiersassertstr(floating_label.hover) =="hover:floating-label"assertstr(floating_label.md) =="md:floating-label"assertstr(floating_label.dark) =="dark:floating-label"# Run the teststest_label_basic_examples()
test_label_for_input_fasthtml_examples
def test_label_for_input_fasthtml_examples():
Test label for input examples from daisyUI v5 documentation.
Exported source
def test_label_for_input_fasthtml_examples():"""Test label for input examples from daisyUI v5 documentation."""from fasthtml.common import Label, Span, Inputfrom cjm_fasthtml_daisyui.components.data_input.text_input import text_input# Label for input at the start label_start = Label( Span("https://", cls=str(label)), Input(type="text", placeholder="URL"), cls=str(text_input) )# Verify structureassert label_start.tag =="label"assert"input"in label_start.attrs['class']# Verify span element span_element = label_start.children[0]assert span_element.tag =="span"assert"label"in span_element.attrs['class']assert span_element.children[0] =="https://"# Verify input element input_element = label_start.children[1]assert input_element.tag =="input"assert input_element.attrs['type'] =="text"assert input_element.attrs['placeholder'] =="URL"# Label for input at the end label_end = Label( Input(type="text", placeholder="domain name"), Span(".com", cls=str(label)), cls=str(text_input) )# Verify structureassert label_end.tag =="label"assert"input"in label_end.attrs['class']# Verify input element comes first input_element = label_end.children[0]assert input_element.tag =="input"assert input_element.attrs['type'] =="text"assert input_element.attrs['placeholder'] =="domain name"# Verify span element comes second span_element = label_end.children[1]assert span_element.tag =="span"assert"label"in span_element.attrs['class']assert span_element.children[0] ==".com"return Div(label_start, label_end)# Run the teststest_label_for_input_fasthtml_examples()