The label associated with the selector when in dropdown mode.
mode
str
Define the way the selector is displayed:
"radio": as a list of radio buttons
"check": as a list of check boxes
any other value: a plain list.
dropdown
bool
False
If True, the list of items is shown in a dropdown menu.
You cannot use the filter in that situation.
selection_message
str dynamic
The message shown in the selection area of a dropdown selector when at least one element is selected. If None, the message is the list of all the selected elements.
multiple
bool
False
If True, the user can select multiple items.
show_select_all
bool
False
If True and multiple is True, the selector shows a "Select all option" button.
filter
bool
False
If True, this control is combined with a filter input area.
A function or the name of the function that transforms an element of lov into a tuple(id:str, label:Union[str, Icon]). The default value is a function that returns the string representation of the lov element.
type
str
Type name of the first lov element
This property is required if lov contains a non-specific type of data (e.g., a dictionary). Then:
value must be of that type
lov must be an iterable containing elements of this type
The function set to adapter will receive an object of this type.
The default value is the type of the first element in lov.
value_by_id
bool
False
If False, the selection value (in value) is the selected element in lov. If set to True, then value is set to the id of the selected element in lov.
on_change
Union[str, Callable]
A function or the name of a function that is triggered when the value changes. The callback function receives the following parameters:
Determines whether the control's value is automatically reflected in the bound application variable. The default value is defined at the application configuration level by the propagate configuration option. If True, any change to the control's value is immediately reflected in the variable.
active
bool dynamic
True
Indicates if this element is active. If False, the element is disabled, and user interaction is not allowed.
id
str
The identifier assigned to the rendered HTML component. This can be used in callbacks or to target the element for styling.
properties
dict[str, Any]
A dictionary of additional properties that can be set to the element.
class_name
str dynamic
A space-separated list of CSS class names to be applied to the generated HTML element. These classes are added to the default taipy-selector class.
hover_text
str dynamic
The text that is displayed when the user hovers over the element.
(★)value is the default property for this visual element.
The value property of the selector is bound to the value variable. This variable
should be set to one of the items in the list, ensuring that the selected value corresponds to one
of the provided list items..
For example:
value="Item 2"
When the user changes the selection, value reflects the new selection in the user's state.
With these settings, the control appears as follows:
You can add a filter input field to display only the strings that match the filter value.
For example, suppose you want to create a selector that allows users to select from a list of all
Python built-in functions. You would use the following code:
This code stores the list of all Python built-in functions (excluding those that start with "_")
in the variable builtin_python_functions. The selection variable is set to the first element of
this list.
Here is how to define a selector control that displays this list:
In this selector, multi-selection is enabled with the multiple property set to
True.
Here is how the control is displayed:
Selector with a long list
An input field (labeled "Search field") appears at the top of the control.
Note that because the list of items is very long, is not fully represented here.
If the user enters the string "ex" in the search field, only the items containing that string are
displayed:
The lov variable is set to an array of three tuples.
The second one ("id2") represents an icon, using the URL to the image along with the label "Taipy."
The definition below uses the lov variable to feed the selector:
When using the lov property, the selector's value property will be set to
the first element of each tuple in the lov. This allows you to retrieve the unique identifier
associated with the selected item (or items).
The selector control allows any type of object to be used in the list of values (lov) set to the
lov property. However, to properly display custom objects, you need to define an
adapter function, which must be set to the adapter property. This function
instructs the selector on how to identify and represent each item in the list.
Assume your application creates a list of User objects in Python as follows:
In this example, a list of User objects is created, with each object having an id, name, and
birth year. The variable user_sel is initialized to the third user, "Peter".
The following definition creates a selector that uses this list:
The users list is set as the value for the selector's lov property.
The value property is bound to the variable user_sel.
The adapter function (set to the adapter property) is a lambda fonction that
converts a User instance (whose type name is set to the type property) into a
tuple:
The first element of the tuple uniquely identifies the item (therefore, those values should be
unique among all items).
In our example, that is simply: u.id.
The second element is the text that the selector displays.
In our example, that is simply: u.name.
Below is how the selector control will appear when using this list of values and adapter function:
Selector using an adapter
The selection (bound to the value property) will be the selected instance of the class
User. This allows your application to directly access the selected User object when a choice is
made.
All selector controls are generated with the "taipy-selector" CSS class. You can use this class to
target selector controls on your page and apply custom styles.
The selector control list is generated as a collection of items grouped in an element that is
assigned the "MuiList-root" class. The descendants (the list items) have the
"MuiListItemButton-root" class applied.
The optional input field used to set a filter includes the "MuiInputBase-root" class.
Here is an example of a CSS rule that applies to selector controls:
.taipy-selector{margin:0px!important;/* Global margin */.MuiInputBase-root{/* Input field */background-color:#572c5f38;color:#221025;border-radius:0px;height:50px}.MuiList-root{/* List */height:70vh;/* Limit height */overflow-y:auto;/* show vertical scroll if necessary */.MuiListItemButton-root:nth-child(even){/* Colors (even) */background-color:lightgrey;color:darkgrey;}.MuiListItemButton-root:nth-child(odd){/* Colors (even) */background-color:darkgrey;color:lightgrey;}}}
This CSS rule:
Changes the color of the filter input field;
Limits the height of the control;
Adds a vertical scrollbar to the selector list if necessary;
Changes the colors used by the list items, alternating between two flavors of gray.
Here is how the selector control looks like when this rule is applied: