diff --git a/panel/widgets/select.py b/panel/widgets/select.py index d3bda7ddd8..baed5fa8e3 100644 --- a/panel/widgets/select.py +++ b/panel/widgets/select.py @@ -31,7 +31,9 @@ CustomMultiSelect as _BkMultiSelect, CustomSelect, RadioButtonGroup as _BkRadioButtonGroup, SingleSelect as _BkSingleSelect, ) -from ..util import PARAM_NAME_PATTERN, indexOf, isIn +from ..util import ( + PARAM_NAME_PATTERN, edit_readonly, indexOf, isIn, +) from ._mixin import TooltipMixin from .base import CompositeWidget, Widget from .button import Button, _ButtonBase @@ -77,12 +79,18 @@ class SingleSelectBase(SelectBase): value = param.Parameter(default=None) + value_label = param.String(allow_None=True, readonly=True) + _allows_values: ClassVar[bool] = True _allows_none: ClassVar[bool] = False _supports_embed: ClassVar[bool] = True + _rename: ClassVar[Mapping[str, str | None]] = { + 'value_label': None, + } + __abstract = True def __init__(self, **params): @@ -91,6 +99,16 @@ def __init__(self, **params): if self.value is None and None not in values and values and not self._allows_none: self.value = values[0] + @param.depends('value', watch=True, on_init=True) + def _update_value_label(self): + try: + idx = indexOf(self.value, self.values) + label = self.labels[idx] + except ValueError: + label = None + with edit_readonly(self): + self.value_label = label + def _process_param_change(self, msg): msg = super()._process_param_change(msg) labels, values = self.labels, self.values