Skip to content

In-place search API

Source: ui/inplace_search.py

Hosts SearchControl as the shared AppBar title over a Home or export TilesContainer without reparenting tiles or changing the route. Prefer calling go_search() / go_back() from Navigation; use this module when wiring the router or debugging search chrome. Concept overview: Body registry and Open search.

In-place set search over the Home/Export tile column (no tile reparenting).

sync_inplace_search_layout

sync_inplace_search_layout(page: Page) -> None

Keep SearchControl width aligned with tiles after open or resize.

Source code in src/learning_app/ui/inplace_search.py
def sync_inplace_search_layout(page: ft.Page) -> None:
    """Keep SearchControl width aligned with tiles after open or resize."""
    state = getattr(page, _PAGE_STATE_ATTR, None)
    if not state:
        return
    search = state["control"]
    if not isinstance(search, SearchControl):
        return
    metrics = LayoutMetricsStore.refresh(page)
    search.apply_flex_layout(metrics)
    AppChrome.get_appbar().center_title = metrics.breakpoint != "compact"
ensure_inplace_search(
    page: Page, body: TilesContainer
) -> bool

Show SearchControl in the shared app bar without reparenting tiles.

Returns:

Type Description
bool

True when search UI was shown (or already active).

Source code in src/learning_app/ui/inplace_search.py
def ensure_inplace_search(page: ft.Page, body: TilesContainer) -> bool:
    """Show SearchControl in the shared app bar without reparenting tiles.

    Returns:
        ``True`` when search UI was shown (or already active).
    """
    if is_inplace_search_active(page):
        return True

    def on_close(_e=None):
        close_inplace_search(page)

    search = SearchControl(page, body, on_close=on_close)
    body.trigger_searching_mode()
    _apply_search_chrome(search)

    import_export = _find_import_export_control(body) if body.export_mode else None
    if import_export is not None:
        import_export.set_tab_bar_visible(False)

    setattr(
        page,
        _PAGE_STATE_ATTR,
        {
            "control": search,
            "body": body,
            "route": page.route or HOME_ROUTE,
            "import_export": import_export,
        },
    )
    sync_inplace_search_layout(page)

    page.update()
    return True
close_inplace_search(page: Page) -> bool

Remove in-place SearchControl and restore the sort bar. Returns True if closed.

Source code in src/learning_app/ui/inplace_search.py
def close_inplace_search(page: ft.Page) -> bool:
    """Remove in-place SearchControl and restore the sort bar. Returns True if closed."""
    state = getattr(page, _PAGE_STATE_ATTR, None)
    if not state:
        return False

    body: TilesContainer = state["body"]
    opened_from_route = state.get("route") or page.route or HOME_ROUTE
    import_export = state.get("import_export")

    if body.searching:
        body.turn_off_searching_mode()

    if import_export is not None:
        import_export.set_tab_bar_visible(True)

    setattr(page, _PAGE_STATE_ATTR, None)
    _restore_shell_chrome(page, opened_from_route)

    page.update()
    return True