Find a component by ID. If neither ``layout`` nor ``page`` is provided, searches the full app layout (preferring ``validation_layout`` for completeness).
(
component_id: str | dict,
layout: Component | None = None,
page: str | None = None,
)
| 122 | |
| 123 | |
| 124 | def find_component( |
| 125 | component_id: str | dict, |
| 126 | layout: Component | None = None, |
| 127 | page: str | None = None, |
| 128 | ) -> Component | None: |
| 129 | """Find a component by ID. |
| 130 | |
| 131 | If neither ``layout`` nor ``page`` is provided, searches the full |
| 132 | app layout (preferring ``validation_layout`` for completeness). |
| 133 | """ |
| 134 | if page is not None: |
| 135 | layout = _resolve_page_layout(page) |
| 136 | |
| 137 | if layout is None: |
| 138 | app = get_app() |
| 139 | layout = getattr(app, "validation_layout", None) or app.get_layout() |
| 140 | |
| 141 | for comp, _ in traverse(layout): |
| 142 | if getattr(comp, "id", None) == component_id: |
| 143 | return comp |
| 144 | return None |
| 145 | |
| 146 | |
| 147 | def parse_wildcard_id(pid: Any) -> dict | None: |
searching dependent graphs…