Overview
renderSwitch(cases) walks an ordered list of branches and returns the first match. Each branch is either a [condition, template] tuple or a bare TemplateResult fallback.
If nothing matches and there is no fallback, it returns nothing so the call site produces no DOM.
Compared to other conditionals
|
API
|
Branches
|
Notes
|
|---|---|---|
cond ? a : b
| 2-way | Fine for simple toggles. |
animatedIf
| 2-way + motion | Use when enter/exit animation matters. |
renderSwitch
| N-way | First truthy tuple wins; optional trailing TemplateResult default. |
Tab navigation with renderSwitch
renderSwitch evaluates each [condition, template] tuple in order and renders the first truthy match. A plain TemplateResult at the end of the array is used as the fallback when no case matches.
Fallback branch
A bare TemplateResult at the end acts as the default when no condition matches.