Skip to main content

Dropdown

A dropdown control that allows users to select a single option from a list of options.

Example:

ft.Dropdown(
width=220,
value="alice",
options=[
ft.DropdownOption(key="alice", text="Alice"),
ft.DropdownOption(key="bob", text="Bob"),
],
)
Dropdown
Basic Dropdown

Inherits: LayoutControl

Properties

Events

  • on_blur - Called when the control has lost focus.
  • on_focus - Called when the control has received focus.
  • on_select - Called when the selected item of this dropdown has changed.
  • on_text_change - Called when the text input of this dropdown has changed.

Methods

  • focus - Requests focus for this control.

Examples

Live example

Color selection with filtering

import flet as ft


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

def get_options() -> list[ft.DropdownOption]:
colors = [
ft.Colors.RED,
ft.Colors.BLUE,
ft.Colors.YELLOW,
ft.Colors.PURPLE,
ft.Colors.LIME,
]
return [
ft.DropdownOption(
key=color.value,
content=ft.Text(value=color.value, color=color),
)
for color in colors
]

def handle_dropdown_select(e: ft.Event[ft.Dropdown]):
e.control.color = e.control.value

page.add(
ft.SafeArea(
content=ft.Dropdown(
editable=True,
label="Color",
options=get_options(),
on_select=handle_dropdown_select,
),
)
)


if __name__ == "__main__":
ft.run(main)
color-selection-with-filtering

Icon selection

import flet as ft


def main(page: ft.Page):
def get_options() -> list[ft.DropdownOption]:
icons = [
{"name": "Smile", "icon": ft.Icons.SENTIMENT_SATISFIED_OUTLINED},
{"name": "Cloud", "icon": ft.Icons.CLOUD_OUTLINED},
{"name": "Brush", "icon": ft.Icons.BRUSH_OUTLINED},
{"name": "Heart", "icon": ft.Icons.FAVORITE},
]
return [
ft.DropdownOption(key=icon["name"], leading_icon=icon["icon"])
for icon in icons
]

page.add(
ft.SafeArea(
content=ft.Dropdown(
border=ft.InputBorder.UNDERLINE,
enable_filter=True,
editable=True,
leading_icon=ft.Icons.SEARCH,
label="Icon",
options=get_options(),
),
)
)


if __name__ == "__main__":
ft.run(main)
icon-selection

Styled dropdowns

import flet as ft


def main(page: ft.Page):
page.add(
ft.SafeArea(
content=ft.Column(
controls=[
ft.Dropdown(
text_size=20,
content_padding=10,
color=ft.Colors.PURPLE_200,
bgcolor=ft.Colors.BLUE_200,
filled=True,
border_radius=30,
border_color=ft.Colors.GREEN_800,
focused_border_color=ft.Colors.GREEN_ACCENT_400,
focused_border_width=5,
options=[
ft.DropdownOption("a", "Item A"),
ft.DropdownOption("b", "Item B"),
ft.DropdownOption("c", "Item C"),
],
),
ft.Dropdown(
border_radius=30,
filled=True,
fill_color=ft.Colors.RED_400,
border_color=ft.Colors.TRANSPARENT,
bgcolor=ft.Colors.RED_200,
color=ft.Colors.CYAN_400,
focused_border_color=ft.Colors.PINK_300,
focused_border_width=20,
options=[
ft.DropdownOption("a", "Item A"),
ft.DropdownOption("b", "Item B"),
ft.DropdownOption("c", "Item C"),
],
),
ft.Dropdown(
border_color=ft.Colors.PINK_ACCENT,
focused_border_color=ft.Colors.GREEN_ACCENT_400,
focused_border_width=25,
border_radius=30,
width=150,
border_width=5,
options=[
ft.DropdownOption("a", "Item A"),
ft.DropdownOption("b", "Item B"),
ft.DropdownOption("c", "Item C"),
],
),
ft.Container(
padding=ft.Padding.only(bottom=20),
content=ft.Dropdown(
text_size=30,
color=ft.Colors.ORANGE_ACCENT,
border_radius=20,
filled=True,
border_width=0,
autofocus=True,
focused_border_color=ft.Colors.GREEN_100,
focused_border_width=10,
width=200,
height=50,
options=[
ft.dropdown.Option("a", "Item A"),
ft.dropdown.Option("b", "Item B"),
ft.dropdown.Option("c", "Item C"),
],
),
),
ft.Dropdown(
text_size=30,
border_radius=20,
filled=True,
border_width=0,
focused_border_color=ft.Colors.GREEN_100,
focused_border_width=10,
content_padding=20,
width=200,
options=[
ft.DropdownOption(
key="a",
text="Item A",
style=ft.ButtonStyle(
shape=ft.BeveledRectangleBorder(radius=15),
color={
ft.ControlState.HOVERED: ft.Colors.WHITE,
ft.ControlState.FOCUSED: ft.Colors.BLUE,
ft.ControlState.DEFAULT: ft.Colors.BLACK,
},
),
),
ft.DropdownOption(
key="b",
text="Item B",
style=ft.ButtonStyle(
shape=ft.BeveledRectangleBorder(radius=15),
color={
ft.ControlState.HOVERED: ft.Colors.WHITE,
ft.ControlState.FOCUSED: ft.Colors.BLUE,
ft.ControlState.DEFAULT: ft.Colors.BLACK,
},
),
),
ft.DropdownOption(
key="c",
text="Item C",
style=ft.ButtonStyle(
shape=ft.BeveledRectangleBorder(radius=15),
color={
ft.ControlState.HOVERED: ft.Colors.WHITE,
ft.ControlState.FOCUSED: ft.Colors.BLUE,
ft.ControlState.DEFAULT: ft.Colors.BLACK,
},
),
),
],
),
],
),
)
)


if __name__ == "__main__":
ft.run(main)

Properties

autofocusclass-attributeinstance-attribute

autofocus: bool = False

Whether the control will be selected as the initial focus. If there is more than one control on a page with autofocus set, then the first one added to the page will get focus.

bgcolorclass-attributeinstance-attribute

bgcolor: Optional[ControlStateValue[ColorValue]] = None

The background color of the dropdown menu in various ControlState states.

borderclass-attributeinstance-attribute

border: Optional[InputBorder] = None

Border around input.

Defaults to InputBorder.OUTLINE.

border_colorclass-attributeinstance-attribute

border_color: Optional[ColorValue] = None

Border color.

Tip

Set to flet.Colors.TRANSPARENT to hide the border.

border_radiusclass-attributeinstance-attribute

border_radius: Optional[BorderRadiusValue] = None

The border radius applied to the corners of the dropdown input field. Accepts a value in virtual pixels or a BorderRadiusValue object. If set to None, the default border radius defined by the theme or system is used.

border_widthclass-attributeinstance-attribute

border_width: Number = 1

The width of the border in virtual pixels.

Tip

Set to 0 to completely remove the border.

capitalizationclass-attributeinstance-attribute

capitalization: Optional[TextCapitalization] = None

Configures how the text input should be capitalized.

colorclass-attributeinstance-attribute

color: Optional[ColorValue] = None

Text color.

content_paddingclass-attributeinstance-attribute

content_padding: Optional[PaddingValue] = None

The padding for the input decoration's container.

denseclass-attributeinstance-attribute

dense: bool = False

Whether the TextField is part of a dense form (i.e., uses less vertical space).

editableclass-attributeinstance-attribute

editable: bool = False

Whether the dropdown allows editing of the text input field.

elevationclass-attributeinstance-attribute

elevation: Optional[ControlStateValue[Optional[Number]]] = 8

The dropdown's menu elevation in various ControlState states.

enable_filterclass-attributeinstance-attribute

enable_filter: bool = False

Determine if the menu list can be filtered by the text input. Defaults to false.

If set to true, dropdown menu will show a filtered list. The filtered list will contain items that match the text provided by the input field, with a case-insensitive comparison.

enable_search: bool = True

Determine if the first item that matches the text input can be highlighted.

error_styleclass-attributeinstance-attribute

error_style: Optional[TextStyle] = None

The TextStyle to use for error_text.

error_textclass-attributeinstance-attribute

error_text: Optional[str] = None

Text that appears below the input border.

If non-null, the border's color animates to red and the helper_text is not shown.

expanded_insetsclass-attributeinstance-attribute

expanded_insets: Optional[PaddingValue] = None

The insets for the expanded dropdown menu.

fill_colorclass-attributeinstance-attribute

fill_color: Optional[ColorValue] = None

Background color of the dropdown input text field.

Note

Will not be visible if filled=False.

filledclass-attributeinstance-attribute

filled: bool = False

Whether the decoration's container is filled with theme fill_color.

focused_border_colorclass-attributeinstance-attribute

focused_border_color: Optional[ColorValue] = None

Border color in focused state.

focused_border_widthclass-attributeinstance-attribute

focused_border_width: Optional[Number] = None

Border width in focused state.

helper_styleclass-attributeinstance-attribute

helper_style: Optional[TextStyle] = None

The TextStyle to use for helper_text.

helper_textclass-attributeinstance-attribute

helper_text: Optional[str] = None

Text that provides context about the input's value, such as how the value will be used.

If non-null, the text is displayed below the input decorator, in the same location as error_text. If a non-null error_text value is specified then the helper text is not shown.

hint_styleclass-attributeinstance-attribute

hint_style: Optional[TextStyle] = None

The TextStyle to use for hint_text.

hint_textclass-attributeinstance-attribute

hint_text: Optional[str] = None

Text that suggests what sort of input the field accepts.

Displayed on top of the input when it's empty and either (a) label is null or (b) the input has the focus.

hover_colorclass-attributeinstance-attribute

hover_color: Optional[ColorValue] = None

The color of the dropdown input text field when hovered.

input_filterclass-attributeinstance-attribute

input_filter: Optional[InputFilter] = None

A filter to apply to the text input field.

labelclass-attributeinstance-attribute

label: Optional[StrOrControl] = None

Optional text that describes the input field.

When the input field is empty and unfocused, the label is displayed on top of the input field (i.e., at the same location on the screen where text may be entered in the input field). When the input field receives focus (or if the field is non-empty) the label moves above, either vertically adjacent to, or to the center of the input field.

label_styleclass-attributeinstance-attribute

label_style: Optional[TextStyle] = None

The label's text style.

leading_iconclass-attributeinstance-attribute

leading_icon: Optional[IconDataOrControl] = None

An optional Icon at the front of the text input field inside the decoration box.

If this is not null, the menu items will have extra paddings to be aligned with the text in the text field.

menu_heightclass-attributeinstance-attribute

menu_height: Optional[Number] = None

The height of the dropdown menu.

If this is None, the menu will display as many items as possible on the screen.

menu_styleclass-attributeinstance-attribute

menu_style: Optional[MenuStyle] = None

The menu style that defines the visual attributes of the menu.

The default width of the menu is set to the width of the text field.

menu_widthclass-attributeinstance-attribute

menu_width: Optional[Number] = None

The width of the dropdown menu.

If this is None, the menu width will be the same as input textfield width.

optionsclass-attributeinstance-attribute

options: list[DropdownOption] = field(default_factory=list)

A list of options to display in the dropdown.

selected_suffixclass-attributeinstance-attribute

selected_suffix: Optional[Control] = None

A control to display after the selected item in the dropdown.

selected_trailing_iconclass-attributeinstance-attribute

selected_trailing_icon: Optional[IconDataOrControl] = None

An optional icon at the end of the text field to indicate that the text field is pressed.

textclass-attributeinstance-attribute

text: Optional[str] = None

The text entered in the text field.

text_alignclass-attributeinstance-attribute

text_align: TextAlign = TextAlign.START

The text align for the TextField of the Dropdown.

text_sizeclass-attributeinstance-attribute

text_size: Optional[Number] = None

Text size in virtual pixels.

text_styleclass-attributeinstance-attribute

text_style: Optional[TextStyle] = None

The TextStyle to use for text in input text field.

trailing_iconclass-attributeinstance-attribute

trailing_icon: Optional[IconDataOrControl] = None

An icon to display at the end of the text field.

valueclass-attributeinstance-attribute

value: Optional[str] = None

The key of the dropdown options corresponding to the selected option.

Events

on_blurclass-attributeinstance-attribute

on_blur: Optional[ControlEventHandler[Dropdown]] = None

Called when the control has lost focus.

on_focusclass-attributeinstance-attribute

on_focus: Optional[ControlEventHandler[Dropdown]] = None

Called when the control has received focus.

on_selectclass-attributeinstance-attribute

on_select: Optional[ControlEventHandler[Dropdown]] = None

Called when the selected item of this dropdown has changed.

on_text_changeclass-attributeinstance-attribute

on_text_change: Optional[ControlEventHandler[Dropdown]] = None

Called when the text input of this dropdown has changed.

Methods

focusasync

focus()

Requests focus for this control.