KScript docs
EN

Components

Focus, growing text and pending classes

Three directives cover browser behaviour that would otherwise need a script:

Directive What it does
@focus() Gives the element focus when it appears.
@focus($t.id == $new_todo) Gives the element focus each time its condition turns true, such as the row an action just added.
@autogrow() Makes a <textarea> as tall as its text. It uses CSS field-sizing where the browser has it and resizes on input where it doesn't.
@pending('saving') Adds the class to the element while any of the component's actions runs, and takes it off when the action finishes or fails.
@pending('crumple', for: 'delete') Adds the class only while an action that runs delete is in flight. for: takes a method name or a list, such as for: ['save', 'delete'].
HTML page
<article class="note" @pending('crumple', for: 'delete')>
  <textarea @autogrow() @on-change($this->edit($event.value))>{$note.body}</textarea>
  <for each="t" in="$note.todos">
    <input value="{$t.text}" @focus($t.id == $focus_todo)>
  </for>
  <button type="button" @on-click($delete)>Delete</button>
</article>

A handler runs delete when it is $delete, call: $delete or a statement that calls $this->delete(...). kscript check reports a for: method that no handler runs, a condition that isn't a bool and @autogrow() on anything but a textarea. The HTML spellings are focus, focus="{$cond}", autogrow and pending="'saving'".

@pending is the class form of live-loading, which shows and hides an element. Use it for an animation while an action runs, and wrap the animation in @media (prefers-reduced-motion: no-preference) in your stylesheet so visitors who ask for less motion don't get it.