Skip to content

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 →

Tag inputTag input
  • 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 pz
from 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"])
Tag input: EmptyTag input: Empty
Empty
Code
pz.container(ui.tag_input([], on_change, placeholder="Add a tag…"), width=320)
Tag input: With tagsTag input: With tags
With tags
Code
pz.container(ui.tag_input(["design", "rust"], on_change), width=320)
Tag input: suggestions=Tag input: suggestions=
suggestions=
Code
pz.container(ui.tag_input(["design"], on_change, text="py", suggestions=["python", "pyzed", "rust"]), width=340)
Tag input: tint="success"Tag input: tint="success"
tint="success"
Code
pz.container(ui.tag_input(["approved", "ready"], on_change, tint="success"), width=320)
Tag input: max_tags=2Tag input: max_tags=2
max_tags=2
Code
pz.container(ui.tag_input(["one", "two"], on_change, max_tags=2), width=320)
Tag input: disabled=TrueTag input: disabled=True
disabled=True
Code
pz.container(ui.tag_input(["design", "rust"], on_change, disabled=True), width=320)

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().

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"])
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).

Full reference →