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…
Form-associated comment form composing <markdown-editor> with Submit/Cancel buttons. Standalone or as the reply-form template inside <comment-thread>.
Overview
<comment-box> is a small form-associated primitive that wraps <markdown-editor> with the canonical Submit / Cancel button row. It's used standalone for top-level comment forms or as the reply-form template inside a <comment-thread>.
The component is presentational with respect to persistence. It fires comment-box:submit and you make the network call; hand the request to e.detail.waitUntil() and the box stays busy until it settles, clearing on success and keeping the text on failure. See Submit contract.
When to use which primitive
Use this
When
<comment-box>
You want a standalone comment / reply form with Submit + Cancel and form participation.
Single-line chat input with send. Different shape from a paragraph comment.
Basic usage
Default
1
<comment-boxname="comment"placeholder="Add a comment…"></comment-box>
The component auto-creates the inner <markdown-editor> + <textarea> for you and forwards placeholder to it. If you need pre-existing markdown content, use the valueattribute or provide your own <markdown-editor> child explicitly. name stays on the host: the host is the form field, so the inner textarea is left unnamed and the value submits once.
Accessible name
The editor textarea is named by the labelattribute. Without one it uses the text of an associated <label for> (the host is a form-associated, labelable element), and falls back to “Comment”.
Naming the editor
123456
<comment-boxlabel="Reply to Ada"placeholder="Write a reply…"></comment-box><form-field><labelfor="body-box">Comment body</label><comment-boxid="body-box"name="body"required></comment-box></form-field>
Edit mode
Pre-fill via value and add the Cancel button via data-show-cancel. Customize the Submit label.
When it has children the tool row is a labelled group (role="group", “Comment tools”); it has no arrow-key roving, so it does not claim role="toolbar". You wire the click handlers; the comment-box doesn't interpret them. The slotted buttons are kept when the comment-box is moved.
Length validation + counter
Set data-min-length and / or data-max-length. When data-max-length is set, a counter is rendered next to the buttons. It is not announced on every keystroke: a status message speaks only within 10% (at least 10 characters) of the limit and when over it.
Submitting an invalid value does not fire comment-box:submit; the browser's validation message is shown on the editor and focus moves there, so the blocked submit is never silent.
280-char limit
1
<comment-boxdata-min-length="3"data-max-length="280"placeholder="Up to 280 chars…"></comment-box>
Form participation
The component is form-associated via ElementInternals. Drop it inside any <form> with name set, and the markdown source submits like any other field.
comment-box:submit is dispatched synchronously, so the box decides what to do as soon as your handler returns. Calling preventDefault() after an await is too late: by then the event has finished and the value has already been cleared. Pick one of three outcomes inside the handler:
In your handler
What the box does
Nothing
Clears the value right after the event.
e.detail.waitUntil(promise)
Goes busy (aria-busy="true", Submit aria-disabled, editor read-only) until the promise settles. Resolve: clears. Reject: keeps the text and refocuses the editor for a retry.
e.preventDefault()
Keeps the value and does nothing else. Call clear() yourself when appropriate (e.g. client-side checks you handle synchronously).
Wiring with retry
12345678
box.addEventListener('comment-box:submit', (e) => {const request = api.postComment(e.detail.value); e.detail.waitUntil(request); // busy until settled; clears on success request.catch(() => {showToast('Failed — your comment is still there, try again'); });});
waitUntil() must be called while the event is dispatching (synchronously in the handler); calling it later throws an InvalidStateError.
Keyboard
Key
Action
Cmd/Ctrl + Enter
Submit (matches GitHub / Slack convention).
Escape
With data-show-cancel: fire comment-box:cancel, as the Cancel button does. Not handled inside the toolbar, or in an editor that has data-tab-indent.
Tab
Move from editor to toolbar buttons to Submit / Cancel.