Skip to content

Dropdown: value not updated and on_change not triggered on keyboard selection (Enter key) when enable_filter=True #5338

@nilton-medeiros

Description

@nilton-medeiros

Duplicate Check

Describe the bug

When using an ft.Dropdown component with enable_filter=True, selecting an option using the keyboard (navigating with arrow keys and pressing Enter) visually updates the displayed text in the dropdown, but the value attribute of the dropdown control remains None (or its previous value). Consequently, the on_change event is not triggered for this type of interaction. Selecting an option with a mouse click works as expected, updating the value and triggering on_change.

Code sample

Code
   import flet as ft

   def main(page: ft.Page):
       def on_dd_change(e: ft.ControlEvent):
           dd_value = e.control.value
           selected_opt_text = "N/A"
           if dd_value:
               # Find the text of the selected option
               selected_opt = next((opt for opt in dd.options if opt.key == dd_value), None)
               if selected_opt:
                   selected_opt_text = selected_opt.text
           
           txt_value.value = f"Dropdown value: {dd_value} (Selected text: {selected_opt_text})"
           txt_value.update()
           print(f"on_change triggered. Dropdown value: {dd_value}") # For console confirmation

       dd = ft.Dropdown(
           label="Test Dropdown",
           hint_text="Select an option",
           options=[
               ft.dropdown.Option(key="ID1", text="Option 1"),
               ft.dropdown.Option(key="ID2", text="Option 2"),
               ft.dropdown.Option(key="ID3", text="Option 3"),
           ],
           on_change=on_dd_change,
           enable_filter=True # Problem observed with this enabled
       )
       txt_value = ft.Text("No selection yet.")

       page.add(dd, txt_value)

   ft.app(target=main)

To reproduce

  1. Click on the dropdown to open it (or tab into it and press space/enter).
  2. If the filter input appears, you can type to filter, or just use arrow keys.
  3. Use the arrow keys (up/down) to navigate to an option.
  4. Press the Enter key to select the highlighted option.
  5. Observe the ft.Text below the dropdown and the console output.

Expected behavior

After pressing Enter on a keyboard-selected option:

The dd.value attribute should be updated to the key of the selected ft.dropdown.Option.
The on_dd_change callback function should be triggered.
The ft.Text control (txt_value) should display the updated value and selected text.
A message should be printed to the console indicating on_change was triggered.

Actual behavior After pressing Enter on a keyboard-selected option:

The dropdown visually displays the selected option's text in its input field.
However, the dd.value attribute remains None (or its previous value if one was set by mouse click prior).
The on_dd_change callback function is NOT triggered.
The ft.Text control (txt_value) is NOT updated (or shows the previous state).
No message is printed to the console from the on_change handler for this keyboard interaction.

Screenshots / Videos

2025-05-28.13-36-34.mp4
Captures

[Upload media here]

Operating System

Windows

Operating system details

Microsoft Windows 11 Pro version 10.0.22631 Compilação 22631 browse MS EDGE WEB

Flet version

0.27.6

Regression

No, it isn't

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions