Accessible tabs
Two independent tab sets. Each tab reports a real aria-selected, inactive panels are hidden, one tab is disabled in the HTML, and the "Billing" tab is disabled until a checkbox in the first panel is checked.
A profile form (display name, role, accent, email notifications) and a preview card that follows every change immediately. Native reset restores everything. There is no backend: the Save button is disabled, so neither the button nor Enter submits, and nothing is stored (the test checks storage and cookies).
| name | value | previous | changes |
|---|---|---|---|
| Waiting for the preview to start. | |||
Two-way binding of native controls (text, <select>, radio group, checkbox) to state, and a styled preview, without script.
:has(input[value=violet]:checked) and :has(option:checked).attr(value) reads the initial attribute, not what the user types.maxlength, and implicit submission blocked by the disabled submit button.Copying the typed name into the preview (one input listener). Everything else in this example has a native CSS alternative.
value, selected, checked), the state() initial value, and the preview’s initial text. They must match:
bind: starts from the state;data-accent instead of :when().data-* attributes follow the states and are restored when the card stops matching. Nothing is saved: reload restores the HTML defaults, and nothing goes to localStorage or cookies (tested).<select> stylesheet under style-src 'self'. It happens with a bare <select> and no script, so it is not caused by the library./* ---- state ------------------------------------------------------------------------------ Initial values repeat the HTML defaults: bind: starts from the state, and form reset returns every control and its state to the HTML default. */.profile { --name: state("Ada"); --role: state("Developer"); --notify: state(true); }/* 0.5.2: the accent is also mirrored to the form's data-accent attribute, so plain attribute selectors style the preview (and other scripts or tests can read it). */.profile { --accent: state("teal", bind(data-accent)); }.profile input[name=display_name] { bind: --name; }.profile select[name=role] { bind: --role; }.profile input[name=accent] { bind: --accent; }.profile input[name=notifications] { bind: --notify; }/* ---- preview: real DOM text (text:, 0.5.1) ---------------------------------------------------- The HTML holds the initial preview, shown before the script runs. */.preview { --c: #0f766e; }.profile[data-accent="violet"] .preview { --c: #6d28d9; }.profile[data-accent="amber"] .preview { --c: #b45309; }.card { background: #fff; border-radius: 14px; padding: 20px; border-top: 6px solid var(--c); box-shadow: 0 1px 3px rgb(0 0 0 / 0.1); }.card p { margin: 4px 0; }.avatar { width: 56px; height: 56px; border-radius: 50%; background: var(--c); }.card .name { font-size: 22px; font-weight: 700; text: var(--name); }.profile:when(--name == "") .card .name { color: #888; text: "(no name yet)"; }.card .role { text: var(--role); }.card .accent { color: var(--c); }.card .accent-value { text: var(--accent); }.card .notify-value { text: when(--notify, "on", "off"); }/* attr: (0.5.3): the preview card carries the form's values as data attributes, derived from the form's states (the card owns none). An empty name gives data-name="" (present, empty). */.card { attr: data-name var(--name); attr: data-role var(--role); attr: data-notify when(--notify, "on", "off"); }.card[data-notify="off"] .notify-value { color: #888; }Source: the library's examples/live-form-preview/. style.css from its first section comment; the layout above it runs but is not shown. Written in the 0.8 syntax (on:, bind:, text:, attr:), which 0.9.0 still runs; see Migrating from 0.8 for the 0.9 forms.
Two independent tab sets. Each tab reports a real aria-selected, inactive panels are hidden, one tab is disabled in the HTML, and the "Billing" tab is disabled until a checkbox in the first panel is checked.
A pressed-state toggle button and a disclosure button. Their aria-pressed and aria-expanded attributes are real DOM attributes, kept in sync with Reactive CSS state.
A notifications section whose channel options are disabled while notifications are off, a theme and text-size preview, an "Advanced settings" disclosure, and a native reset. Nothing is saved.