quirl.components.tag

A removable or selectable category/filter tag.

Module Contents

Classes

Tag

A removable or selectable category/filter tag.

API

class quirl.components.tag.Tag(element: Optional[str] = None, properties: Optional[Dict[str, str]] = None, props: Optional[Dict[str, str]] = None, style: Optional[Dict[str, str]] = None, inner_html: Optional[Union[str, str, float]] = None, children: Optional[List[duck.html.components.HtmlComponent]] = None, **kwargs)[source]

Bases: duck.html.components.container.Container

A removable or selectable category/filter tag.

Renders as a small capsule with text, an optional selected state, and an optional dismiss button. Commonly used for filters, categories, or selected items.

Usage:

Tag(tag_text="Python", dismissible=True)
Tag(tag_text="Active", selected=True)

Required Props:

  • tag_text: The tag label text

Optional Props:

  • dismissible: Show a remove button. Defaults to False.

  • selected: Highlight the tag with the accent color. Defaults to False.

  • bg_color: Background color override.

  • color: Text color override.

Initialization

Initialize an HTML component.

Parameters:
  • element – The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.

  • accept_inner_html – Whether the HTML component accepts an inner body (e.g., inner-body-here).

  • inner_html – Inner html to add to the HTML component. Defaults to None.

  • properties – Dictionary for properties to initialize the component with.

  • props – Just same as properties argument (added for simplicity).

  • style – Dictionary for style to initialize the component with.

  • event_handlers – Events to automatically bind. Each dictionary maps an event name to its handler and may include additional keyword arguments forwarded to bind(), e.g. event_handlers=[{"click": on_button_click, **extra_kwargs}].

  • **kwargs – Extra keyword arguments

Raises:

HtmlComponentError – If ‘element’ is not a string or ‘inner_html’ is set but ‘accept_inner_html’ is False.

build_dismiss_button() duck.html.components.button.Button[source]

Build the dismiss button for removable tags.

Returns:

A styled Button component that triggers removal.

docs_animation_steps

None

docs_preview_kwargs

None

on_create()[source]

Build the tag with optional selected state and dismiss button.

async on_dismiss(btn, event, value, ws)[source]

Handle dismiss click by hiding the tag.

Parameters:
  • btn – The dismiss button component.

  • event – The click event name.

  • value – Event payload.

  • ws – The active WebSocket connection.