Tag input
A box of chips with a field at the end. Enter or a comma turns the text into a tag and on_change gets the new list, as it does when the x of a chip is clicked. suggestions offers matching tags under it.
ui.tag_input · Category: Forms · Full reference →


pz.container(ui.tag_input(["design", "rust", "python"], on_change, placeholder="Add a tag…"), width=380)When to use
Section titled “When to use”- For labels, keywords, recipients or any short list the user types.
- For a fixed set of options, use Chip filters or a Drop-down.
import pyzed as pzfrom pyzed import ui
class Labels(pz.App): def __init__(self): self.tags = ["design"] self.typing = ""
def view(self): return ui.tag_input(self.tags, lambda tags: setattr(self, "tags", tags), text=self.typing, on_input=lambda text: setattr(self, "typing", text), suggestions=["python", "rust", "docs"])Variants
Section titled “Variants”Content
Section titled “Content”

Code
pz.container(ui.tag_input([], on_change, placeholder="Add a tag…"), width=320)

Code
pz.container(ui.tag_input(["design", "rust"], on_change), width=320)

suggestions=Code
pz.container(ui.tag_input(["design"], on_change, text="py", suggestions=["python", "pyzed", "rust"]), width=340)

tint="success"Code
pz.container(ui.tag_input(["approved", "ready"], on_change, tint="success"), width=320)States and events
Section titled “States and events”

max_tags=2Code
pz.container(ui.tag_input(["one", "two"], on_change, max_tags=2), width=320)

disabled=TrueCode
pz.container(ui.tag_input(["design", "rust"], on_change, disabled=True), width=320)Events
Section titled “Events”Tag input has 2 events of its own, listed below. Like every widget it also has the 18 common events (click, double_click, right_click, mouse_enter, drag, key_down, resize…), attached with .on(...): see Events and Events of every component.
| Event | Handler gets | When |
|---|---|---|
on_change |
(tags) |
Callable that receives the new list of tags. |
on_input |
(text) |
Callable that receives the text being typed. |
Handler gets is what Pyzed passes to your callable: () means nothing. Any handler can also be a message (a value that is not callable), which goes to update().
Handling the events
Section titled “Handling the events”The same events written three ways. Imperative: methods of the app change self. Declarative: the handlers produce messages and one update() decides. Functional: a pure function draws an immutable state and asks for changes with set_state(...). See Imperative, declarative and functional.
class Labels(pz.App): def __init__(self): self.tags = ["design", "rust"] self.typing = ""
def set_tags(self, tags): # on_change: the new list (a tag added or removed) self.tags = tags
def type(self, text): # on_input: the text in the field self.typing = text
def view(self): return ui.tag_input(self.tags, self.set_tags, text=self.typing, on_input=self.type, placeholder="Add a label…", suggestions=["python", "docs", "bug"])from dataclasses import dataclass
@dataclassclass SetTags: tags: list
@dataclassclass Type: text: str
class Labels(pz.App): tags = ["design"] typing = ""
def update(self, message): match message: case SetTags(tags): self.tags = tags case Type(text): self.typing = text
def view(self): return ui.tag_input(self.tags, SetTags, text=self.typing, on_input=Type)from dataclasses import dataclass
@dataclass(frozen=True)class State: tags: tuple = ("design",) typing: str = ""
def view(state, set_state): return ui.tag_input(state.tags, lambda tags: set_state(tags=tuple(tags)), text=state.typing, on_input=lambda text: set_state(typing=text))Properties and API
Section titled “Properties and API”ui.tag_input
Section titled “ui.tag_input”tag_input( tags, on_change=None, *, text='', on_input=None, placeholder='', suggestions=(), max_tags=None, unique=True, tint='accent', width='fill', disabled=False, id=None, theme=None,)A box of removable chips with a field to type more. Enter or a comma turns the text into a tag; on_change gets the new list, as it does when a chip’s x is clicked.
| Property | Default | Description |
|---|---|---|
tags |
required | Your list of tags. |
text |
"" |
What is being typed (your state too). |
placeholder |
"" |
Hint text shown when empty. |
suggestions |
() |
Tags offered under the field while the text matches them. |
max_tags |
None |
Hides the field once the list has this many. |
unique |
True |
A tag already in the list is not added again. |
tint |
"accent" |
Color of the chips. |
width |
"fill" |
Width: pixels, "fill", "shrink" or "fill:N" (proportion). |
disabled |
False |
Disables it (ignores clicks). |
id |
None |
Stable identifier used to focus or scroll it with a Command. |
theme |
None |
Theme to use instead of the current one (pyzed.theme.current()). |
Events: on_change, on_input (events).