ShowWhen Component

Table of Contents


Introduction

Syntax

tml`
    <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.

Attributes

The ShowWhen component ignores the standard attributes.

Children

The ShowWhen component accepts all children.

Usage

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>
`

DOM element properties

The ShowWhen component is remounted when the hasValue conditions change.