Component API

<comment-composer>

Open live example

GitHub/Slack-style comment composer: a one-line text field that expands
into a multi-line textarea with a bottom-right Cancel/Submit footer
(form-actions) as soon as it's focused or clicked. Submitting fires
submit with the trimmed value, then clears the field and collapses back
to one line — it's meant for posting one comment at a time, not editing a
persistent value in place (see editable-text for that). Canceling (the
Cancel button or Escape) discards the draft and collapses without
firing submit. Clicking away (blur) does neither — the composer stays
expanded until the user explicitly submits or cancels. Cmd/Ctrl+Enter
submits from the textarea, matching editable-text's multiline shortcut —
the Submit button always shows a kbd-hint for it, so the shortcut is
discoverable rather than a hidden power-user feature. Calling the standard
.focus() method expands the composer (if collapsed) and focuses its
field, for an ancestor that wants to drive it programmatically.
Purely token-styled (no bespoke colors), so it's themeable via the same
--ui-* custom properties as every other value-entry field.

Install

import "@f-ewald/components/comment-composer.js";

Usage

<comment-composer placeholder="Add a comment…"></comment-composer>
<script type="module">
  document.querySelector("comment-composer").addEventListener("submit", (e) => {
    postComment(e.detail.value);
  });
</script>

Attributes / properties

PropertyAttributeTypeDefaultDescription
valuevaluestring""Committed value shown in the collapsed one-line field.
placeholderplaceholderstring"Add a comment…"Placeholder text shown when empty.
labellabelstring"Comment"Accessible name applied to the input/textarea.
rowsrowsnumber4Visible row count once expanded.
submitLabelsubmit-labelstring"Submit"Label for the primary submit button.
cancelLabelcancel-labelstring"Cancel"Label for the secondary cancel button.
disableddisabledbooleanfalseDisables the field entirely.

Events

EventDescription
cancelUser discarded the draft via the Cancel button or Escape.
submitUser submitted a non-empty comment; detail: { value: string }.

Slots

None.

CSS custom properties

Custom property
--ui-border
--ui-border-width
--ui-focus-ring
--ui-font
--ui-font-size
--ui-line-height-normal
--ui-radius
--ui-radius-sm
--ui-surface
--ui-text