Create a select component with consistent ID based on label.
(
label: str,
options: list[str],
default: str | None = None,
size: float = 1.0,
component_id: str | None = None,
**kwargs
)
| 678 | |
| 679 | @with_render_tracking("selectbox") |
| 680 | def selectbox( |
| 681 | label: str, |
| 682 | options: list[str], |
| 683 | default: str | None = None, |
| 684 | size: float = 1.0, |
| 685 | component_id: str | None = None, |
| 686 | **kwargs |
| 687 | ) -> ComponentReturn: |
| 688 | """Create a select component with consistent ID based on label.""" |
| 689 | service = PreswaldService.get_instance() |
| 690 | current_value = service.get_component_state(component_id) |
| 691 | if current_value is None: |
| 692 | current_value = ( |
| 693 | default if default is not None else (options[0] if options else None) |
| 694 | ) |
| 695 | |
| 696 | component = { |
| 697 | "type": "selectbox", |
| 698 | "id": component_id, |
| 699 | "label": label, |
| 700 | "options": options, |
| 701 | "value": current_value, |
| 702 | "size": size, |
| 703 | } |
| 704 | |
| 705 | logger.debug(f"[selectbox] ID={component_id}, selected={current_value}") |
| 706 | |
| 707 | return ComponentReturn(current_value, component) |
| 708 | |
| 709 | |
| 710 | @with_render_tracking("separator") |
no test coverage detected