<t-num>
A number the reader can drag, type or step with the keyboard. This is the classic Tangle control.
A
The element's text is the starting value, and also what readers see without JavaScript.
You can use the value attribute instead, which is handy when a format adds symbols,
as in <t-num name="price" value="1000" format="$%,d"></t-num>.
Attributes
| Attribute | Default | Description |
|---|---|---|
name | required | The variable this number shows and changes. |
value | text content | The starting value. Without a value or text, the element is just another view of a variable declared elsewhere (see below). |
min, max | unbounded | The range the reader can drag or type within. |
step | 1 | The increment for dragging and the arrow keys. It also sets the default number of decimals shown. |
format | from step | How the number is displayed. See formats. |
color | accent color | A CSS color, or two ("#246bce #75a7ff") for light and dark mode. Every place the variable appears uses it, formulas included. |
label | the name | The accessible name screen readers announce. |
pixels-per-step | 5 | How far the pointer must travel to change the value by one step. Raise it for finer control. |
previous | A variable to hold the value from before the last drag or edit (starts at the initial value, and updates when a gesture finishes with a new value). |
Try them out: change the attributes in the code, then drag the number below it. This uses
<t-tag>.
Interaction
| Input | Effect |
|---|---|
| Drag left or right | Changes the value by one step every pixels-per-step pixels. Works with touch too. |
| Click without dragging | Opens a small field to type a value. The value is snapped to the step and clamped to the range. |
| → ↑ / ← ↓ | One step up or down. Hold Shift for ten steps. |
| Home / End | Jumps to min or max, if set. |
| Enter or Space | Opens the field to type a value. |
In the typing field, Enter confirms and Esc cancels; clicking away also
confirms. The field accepts expressions, so readers can type w + 1 or 2 * Math.PI.
Hovering a number highlights every place its variable appears on the page, in text and in formulas.
Several views of one variable
Only the first element that declares a variable sets its starting value. Any other <t-num>
with the same name, and with no value of its own, is another handle on the same variable:
Set the budget to
… three paragraphs later …
With your
Drag sensitivity
A drag changes the value by one step every pixels-per-step pixels. If a
range has many steps, lower pixels-per-step so a comfortable drag still covers it.
Raise it when you want precise, slow adjustments.
A learning rate of
Previous value
Give <t-num> a previous attribute to keep the value from before the last drag or typed
edit. While you drag, previous stays put; once you let go, it updates to where the drag
started:
Drag
Notes
- If several elements declare
min,max,steporcolorfor the same variable, the most recently connected one wins. Declare constraints once. - A
<t-num>'sformatalso becomes the variable's default format, for formulas and other views, unless the variable already has one. - For assistive technology the element is a
slider, witharia-valuenow,aria-valuemin,aria-valuemaxandaria-valuetextkept up to date.