Date picker
Overview¶
Date picker allows the user to enter free text or select a date from a calendar widget. and is based on the Angular Material datapicker component.
Examples¶
from dataclasses import field
from datetime import date
import mesop as me
@me.stateclass
class State:
picked_date: date | None = field(default_factory=lambda: date(2024, 10, 1))
def on_load(e: me.LoadEvent):
me.set_theme_mode("system")
@me.page(path="/date_picker", on_load=on_load)
def app():
state = me.state(State)
with me.box(
style=me.Style(
display="flex",
flex_direction="column",
gap=15,
padding=me.Padding.all(15),
)
):
me.date_picker(
label="Date",
disabled=False,
placeholder="9/1/2024",
required=True,
value=state.picked_date,
readonly=False,
hide_required_marker=False,
color="accent",
float_label="always",
appearance="outline",
on_change=on_date_change,
)
me.text("Selected date: " + _render_date(state.picked_date))
def on_date_change(e: me.DatePickerChangeEvent):
state = me.state(State)
state.picked_date = e.date
def _render_date(maybe_date: date | None) -> str:
if maybe_date:
return maybe_date.strftime("%Y-%m-%d")
return "None"
API¶
date_picker
¶
Creates a date picker component.
PARAMETER | DESCRIPTION |
---|---|
label |
Label for date picker input.
TYPE:
|
on_change |
Fires when a valid date value has been specified through Calendar date selection or user input blur.
TYPE:
|
appearance |
The form field appearance style.
TYPE:
|
style |
Style for date picker input.
TYPE:
|
disabled |
Whether it's disabled.
TYPE:
|
placeholder |
Placeholder value.
TYPE:
|
required |
Whether it's required.
TYPE:
|
value |
Initial value.
TYPE:
|
readonly |
Whether the element is readonly.
TYPE:
|
hide_required_marker |
Whether the required marker should be hidden.
TYPE:
|
color |
The color palette for the form field.
TYPE:
|
float_label |
Whether the label should always float or float as the user types.
TYPE:
|
subscript_sizing |
Whether the form field should reserve space for one line of hint/error text (default) or to have the spacing grow from 0px as needed based on the size of the hint/error content. Note that when using dynamic sizing, layout shifts will occur when hint/error text changes.
TYPE:
|
hint_label |
Text for the form field hint.
TYPE:
|
key |
The component key.
TYPE:
|
DatePickerChangeEvent
dataclass
¶
Bases: MesopEvent
Represents a date picker change event.
This event will only fire if a valid date is specified.
ATTRIBUTE | DESCRIPTION |
---|---|
date |
Date value
TYPE:
|
key |
key of the component that emitted this event.
TYPE:
|