Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

dirname

Submits the text direction of a field (ltr or rtl) as an extra form value, so the server can display user-written text in the direction it was typed.

Overview

dirname adds a second entry to the form submission: its name is the attribute's value and its value is the field's directionality, ltr or rtl. When the server later shows that text, it can set dir from the stored value instead of guessing, so Arabic or Hebrew comments display correctly on an English page and the reverse.

Pair it with dir="auto" on the field. Without that, the field simply inherits the page's direction and dirname reports it, whatever the user typed.

Applies to: <textarea> and <input> of type text, search, tel, url, email, password, hidden, submit, reset and button.

Values

ValueMeaning
Any non-empty nameThe name of the extra entry. The convention is the field's name plus .dir.
Absent or emptyNo extra entry (the default).

The submitted value is the element's directionality at submit time:

Field's dirSubmitted
autoFrom the first strong character of the value: rtl for Arabic or Hebrew, otherwise ltr.
ltr / rtlThat value.
Not setInherited from the nearest ancestor with dir, usually ltr from <html>.

On an <input type="submit">, the entry is only sent when that button submits the form, and it reports the button's own directionality. The <button> element does not support dirname.

Examples

Showing the text again, safely

Accept only the two expected values and escape the text itself. Never put either submitted value into the page unescaped.

If you store text without a direction, render it with dir="auto" or inside <bdi>; the browser then detects the direction on display instead.

In Vanilla Breeze

  • VB adds no behaviour to dirname. It is submitted by the browser in every submit mode, including data-validate with data-submit="fetch" or "event", because those build their data with new FormData(form, submitter).
  • VB's form styles are written with logical properties, so a field with dir="auto" mirrors its padding, select chevron, datalist arrow and invalid edge when the user types right-to-left text.

Accessibility

  • Correct direction is a readability issue: punctuation and numbers in mixed text land in the wrong place when the direction is wrong. Setting dir on redisplayed text fixes that for every reader, including screen readers, which use it to choose reading order.
  • dir="auto" on the field also helps the person typing: right-to-left text starts at the correct edge as soon as they type.

Security

Both submitted values are user input. A modified request can send any string as title.dir, so allow-list ltr and rtl before writing it into an attribute, and HTML-escape the text.

Browser support

Baseline 2023: Chrome 17, Safari 6, Firefox 116 (the last to ship, August 2023).

Gotchas

  • Without dir="auto" the answer is the page direction, which makes dirname useless for mixed-language input.
  • The direction is for the whole value, decided by its first strong character. "Hello مرحبا" is ltr.
  • It is not available on <select> or on contenteditable elements.
  • Pick a name that can't clash with another field; the .dir suffix avoids that.

Related

Which to choose

  • dirname + dir="auto" — you store user text and show it again elsewhere.
  • dir="auto" or <bdi> on display — you didn't store a direction; let the browser detect it.
  • lang — you know the language, not just the direction.
↑