Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchBar control #2212

Merged
merged 7 commits into from
Dec 17, 2023
Merged

SearchBar control #2212

merged 7 commits into from
Dec 17, 2023

Conversation

ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Dec 7, 2023

close #1637 and #1808

Test code:

import flet as ft


def main(page):
    page.theme_mode = ft.ThemeMode.LIGHT

    def close_anchor(e):
        text = f"Color {e.control.data}"
        print("closing view from item:", text)
        anchor.close_view(text)
        print(f"Value: {anchor.value}")

    def handle_change(e):
        print("handle_change |  e.data:", e.data)
        print(f"Value: {anchor.value}")

    def handle_submit(e):
        print("handle_submit |  e.data:", e.data)
        print(f"Value: {anchor.value}")

    def handle_tap(e):
        print("handle_tap")
        print(f"Value: {anchor.value}")

    def get_value(e):
        print("get_value")
        print(f"Value: {anchor.value}")
        e.control.text = anchor.value
        page.update()

    anchor = ft.SearchBar(
        value="Default",
        view_elevation=4,
        divider_color=ft.colors.AMBER,
        bar_hint_text="Search colors...",
        view_hint_text="Choose a color from the suggestions...",
        on_change=handle_change,
        on_submit=handle_submit,
        on_tap=handle_tap,
        controls=[
            ft.ListTile(title=ft.Text(f"Color {i}"), on_click=close_anchor, data=i)
            for i in range(10)
        ],
    )

    page.add(
        ft.SafeArea(
            content=ft.Column(
                [
                    ft.Row(
                        alignment=ft.MainAxisAlignment.CENTER,
                        controls=[
                            ft.OutlinedButton(
                                "Open Search View",
                                on_click=lambda _: anchor.open_view(),
                            ),
                            ft.OutlinedButton(
                                "Get Value",
                                on_click=get_value,
                            ),
                        ],
                    ),
                    anchor,
                ]
            )
        )
    )


ft.app(target=main)

@FeodorFitsner FeodorFitsner merged commit b1fbf87 into main Dec 17, 2023
2 checks passed
@ndonkoHenri ndonkoHenri deleted the search-bar branch December 17, 2023 22:48
@andyargg
Copy link

andyargg commented Jan 4, 2024

When you click on the 'X,' it doesn't close. How can i do it?

@ndonkoHenri
Copy link
Contributor Author

Open a new discussion, and share code + capture...

@andyargg
Copy link

andyargg commented Jan 4, 2024

Done

zrr1999 pushed a commit to zrr1999/flet that referenced this pull request Jul 17, 2024
* initial commit

* attempt to add dismiss method

* Create SearchController on init

* SearchAnchor.bar -> SearchAnchor + SearchBar

* open_view and close_view: sync and async

* add value prop

* add value default

---------

Co-authored-by: Feodor Fitsner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SearchAnchor control
3 participants