This page demonstrates all the Datastar attributes available in gomponents-datastar.
Signals are reactive state variables. Click the buttons to modify them.
clicks
The key form of data-signals patches a single signal, and reads the signal name from the attribute key. Unlike the value form, it applies the casing modifiers to that name.
data-signals:my-count="1" creates $myCount.
Value:
data-signals:my-total__case.snake="2" creates $my_total.
Value:
The data-text attribute binds text content to an expression.
Hello, !
The data-bind attribute creates two-way data binding between signals and form elements.
Value:
Selected:
Message length:
Passing modifiers to data-bind emits the key form of the attribute, so Datastar reads the signal name from the attribute key instead of its value.
data-bind:accepted__prop.checked binds the signal to the checked property.
Accepted:
data-bind:search__event.change syncs on change only, so the signal updates when the input loses focus or you press Enter, not on every keystroke.
Search:
The data-show attribute shows or hides elements based on an expression.
Visible:
The data-class attribute adds or removes classes based on expressions.
The data-attr attribute sets attribute values based on expressions.
Clicks: /10
Button disabled:
The data-style attribute sets inline styles based on expressions.
Counter:
The data-computed attribute creates read-only signals based on expressions.
Total: $
The data-effect attribute executes expressions when signals change.
Open the browser console and change the counter to see the effect in action.
The data-init attribute runs expressions when elements are loaded.
Check the browser console to see when this section initialized.
The data-on attribute attaches event listeners to elements.
Clicks:
Hovering:
Debounced value:
The data-on-interval attribute runs expressions at regular intervals.
Seconds elapsed:
The data-on-intersect attribute runs expressions when elements enter the viewport.
Scroll down to see the intersection observer in action...
Intersected:
The data-ref attribute creates signals that reference DOM elements.
The data-preserve-attr attribute preserves attribute values during DOM morphing.
This content is inside a details element. The 'open' attribute is preserved during DOM updates.
The data-ignore attribute tells Datastar to ignore an element and its descendants.
The data-ignore-morph attribute prevents elements from being morphed during DOM updates.
The data-on-signal-patch attribute runs expressions when signals are patched.
Open the console and change the counter to see signal patch events.
Built with gomponents and Datastar