ShowWhen ComponentHideWhen Component Referencetml`
<ShowWhen hasValue=stateVariable1>
...
</ShowWhen>
`tml`
<ShowWhen hasValue="stateVariable1,stateVariable2">
...
</ShowWhen>
`
tml`
<ShowWhen hasValue=${SV.find(/stateVariable\d+/)}>
...
</ShowWhen>
`
The ShowWhen component displays its children whenever any of the state variables specified by the hasValue attribute have truthy values.
Otherwise, the children are not rendered.
The ShowWhen component ignores the standard attributes.
hasValue
The hasValue attribute can accept:
The hasValue attribute will accept the output of SV.find(). Any argument acceptable to SV.find() is acceptable as a value of the hasValue attribute.
The ShowWhen component accepts all children.
ShowWhen is often useful to show an error message area when there is an error and hide it when there is no error. For example:
tml`
<ShowWhen hasValue=myPage_errorMsg>
<div>Error: {{myPage_errorMsg}}</>
</ShowWhen>
`
The ShowWhen component is remounted when the hasValue conditions change.
hasValue conditions are met, the Component renders the children.hasValue conditions are not met, the Component renders a single <span> with the class whenMarker. This allows the Component to keep a placeholder for any future template nodes.