Skip to content
ReferenceCoreShow an unordered list from a Python list.

BulletedList

Group: Lists

Description

A BulletedList turns a Python list into a bulleted list on the page, one bullet per item. It is the usual way to show a collection from your state when order does not matter.

Syntax

BulletedList(items)

Parameters

Parameter Type Default Meaning
items list required One entry per bullet. Items can be strings, numbers, booleans, or components; each gets its own line automatically.

Like every component, BulletedList also accepts styling and attribute keywords.

Examples

A list straight from state, growing as the visitor adds to it:

from drafter import *
from dataclasses import dataclass


@dataclass
class State:
    supplies: list[str]


@route
def index(state: State) -> Page:
    return Page(state, [
        Header("Expedition Supplies"),
        BulletedList(state.supplies),
        "Add an item:",
        TextBox("item"),
        "\n",
        Button("Pack it", "pack")
    ])


@route
def pack(state: State, item: str) -> Page:
    state.supplies.append(item)
    return index(state)


start_server(State(["rope", "lantern"]))

Notes

  • Numbers and booleans display as their text form, but structured items (like dataclasses) need to be converted first: build a list of strings with a loop (for pet in state.pets: ... names.append(pet.name)) and pass that list instead. For rows of structured data, a Table is usually clearer.
  • An empty list renders as nothing at all. If an empty list deserves an explanation, use an if in your route to show a message like "Nothing packed yet.\n" instead of the empty list.
  • In tests, compare structurally: assert_has(index(State(["rope"])), BulletedList(["rope"])).