Triggers
triggersince 0.20.8 syntaxThe events on: can listen for: click(), change(), input(), pointerenter(), pointerleave(), focus() and blur(), plus key() and outside().
On this page · 8 sections+−
Caution · 0.8.x compatibility syntax
This page documents 0.8 syntax that Reactive CSS 0.9.0 still runs. New code uses the 0.9 form: see Legacy 0.8.x compatibility.
Syntax
on: click(<action>#), focus(<action>#), …;registry syntax: click(action, ...)
Parameters
- click() change() input()eventbubbling
- Run on the target and its ancestors, innermost first.
- pointerenter() pointerleave() focus() blur()eventtarget only
- Run on the target element only.
Effect
Each trigger runs its actions when the event fires.
Example
.tabs { --active: state(1);}.tab:on(click) { --active: set(sibling-index());}.panel { display: none;}.panel:nth-var(--active) { display: block;}.tab:nth-var(--active) { border-color: currentColor;}state()Function · hover any red tokenMakes each matching element the owner of an independent state with an initial value.Reference →
Resultvisual only
waiting for interaction
Behavior
- 0.9. Each trigger becomes an
:on()rule:.tab:on(click) { --active: set(sibling-index()); }.:on()accepts 32 events, among themdblclick,pointerdown,keyup,submitandscroll. Theseon:triggers keep working in 0.9. - Keyboard activation of a
<button>firesclick, so buttons work with Enter and Space. - Label clicks, Space and mouse clicks all fire
changeon checkboxes.
Supported contexts
- Inside
on:.
Limitations
- Only these events are supported by
on:. Theon()value function accepts a longer list.
Related
Experimental · syntax may change between minor versions