TemplateField

TemplateField

HkTemplateField is the editing half of the fill-template surfaces: a single-line rich input for values that mix literal text with {{ token }} placeholders. Typing {{ opens the vocabulary panel, picking a row inserts the placeholder as an inline chip, and clicking a chip opens the chip editor. The model is and stays the plain {{ token }} string — chips are a rendering of the value, never a second data format, and serialization is byte-exact, so a round trip through this field never rewrites a stored value.

  • To show a stored template, use HkTemplateText, the read-only half of the same grammar.
  • A plain text value is an HkInput; an ordered set of tag keys is HkTagInput.

Import

tsx
1
import { HkTemplateField, type HkTemplateTokenDef } from "@celestia-island/hikari";
rust
1
2
use hikari_components::*;          // TemplateField, TemplateTokenDef, TemplateText
use hikari_components::prelude::*; // rsx!, VNode, EventHandler

Literal text and chips

modelValue is the raw template, verbatim from storage, and update:modelValue carries the full next value. Every {{ word }} with a bare identifier becomes a chip that spells the canonical {{ name }} form while it keeps the exact source it was parsed from.

Type {{ to pick a placeholder.

The chip editor is a popover on desktop and a bottom sheet on a phone; it can swap the placeholder for another vocabulary entry, read what it fills from, or remove it, and focus moves into that form. The Rust mirror renders the editor's form body in place, and the host owns the open/close state.

Grouped vocabulary

groupLabel maps a token's group key to the heading shown over its run of rows, in both the vocabulary panel and the chip editor. Without it the key is passed through verbatim — groups are consumer-defined technical keys, so the library has no opinion on their wording. A token without a group is not a section of its own: it renders under the previous heading's band.

Label, hint, error and states

label names the field and points at the editable, so a click on the caption focuses it; hint is the muted helper line and is hidden while an error shows; error adds the error face to the box and its own line (an empty string is no error). disabled drops contenteditable, and submitOnEnter is the enter intent when no suggestion row is active — the same contract as the input family.

Literal text stays as typed.

A placeholder is not closed

API

Vue

Props

NameTypeDefaultRequired
modelValueString""—
tokensArray as PropType<readonly HkTemplateTokenDef[]>() => []—
labelStringundefined—
hintStringundefined—
errorStringundefined—
placeholderString""—
disabledBooleanfalse—
submitOnEnterFunctionundefined—
groupLabelFunction as PropType<(group: string) => string>undefined—

Emits

EventPayload
update:modelValuestring

Rust

Props — TemplateField

PropTypeDefaultDescription
model_valueStringString::new()The raw {{ token }} value, verbatim from storage (Vue modelValue, default "").
tokensVec<TemplateTokenDef>Vec::new()Vocabulary offered by the panel + chip editor (Vue tokens, the shared HkTemplateTokenDef of templateGrammar.ts — the same TemplateTokenDef the read-only TemplateText renders from).
labelOption<String>NoneField caption; points the label at the editable (label clicks focus, screen readers announce the field by name).
hintOption<String>NoneMuted helper line under the field (hidden while an error shows).
errorOption<String>NoneError line + the box's error face (an EMPTY string is no error, exactly Vue's truthiness).
placeholderStringString::new()The :empty placeholder of the editable (Vue placeholder, default "").
disabledboolfalse—
submit_on_enterOption<EventHandler<()>>NoneSubmit intent on Enter (when no suggestion row is active) — the same contract as Input.
group_labelOption<Rc<dyn Fn(&str) -> String>>NoneMaps a token's group key to the heading label shown over its run (Vue: the groupLabel FUNCTION prop).
idOption<String>NoneElement id of the editable (Vue generates one with useId); also seeds the panel-rows / row ids.
panel_anchorOption<PopoverAnchorRect>NoneThe trigger rect to anchor the vocabulary panel against (feedback::popover::anchor_rect_from_element_id measures one by id); None pins the popout to the nearest positioned ancestor.
panel_offsetf646.0Gap between the field and the vocabulary panel (Vue: HkMenu's offset default 6).
suggest_openboolfalseVocabulary panel visibility (Vue: suggestOpen).
suggest_queryStringString::new()The typed identifier inside the live {{ query trigger (Vue: suggestQuery) — the panel's filter input.
suggest_activei320The panel's keyboard cursor: an index into the FILTERED rows (Vue: suggestActive).
triggerOption<TemplateFieldTrigger>NoneThe live trigger's serialized span (Vue: triggerRange) — what a pick replaces.
editor_openboolfalseChip editor visibility (Vue: editorOpen).
editor_chipOption<usize>NoneThe chip the editor edits, by token-segment index (Vue holds the DOM element).
editor_tokenStringString::new()The token name the editor shows (Vue: editorToken).
editor_queryStringString::new()The editor's search query (Vue: editorQuery).
onupdate_model_valueOption<EventHandler<String>>NoneVue: update:modelValue — the full next value.
oncaretOption<EventHandler<usize>>NoneThe caret writer: every pick / apply / remove emits the serialized offset editing resumes at (Vue parks the caret itself; see the header's engine delta).
on_inputOption<EventHandler<InputEvent>>NoneThe editable's RAW input event, forwarded untouched — the host normalizes through the pure algebra and writes model_value back (see the header's engine delta).
on_suggest_open_changeOption<EventHandler<bool>>NoneFires with the desired panel state (Vue: HkMenu's update:open).
on_suggest_activeOption<EventHandler<i32>>NoneThe keyboard cursor's writer (Vue: the local suggestActive writes).
on_editor_open_changeOption<EventHandler<bool>>NoneFires with the desired editor state (Vue: HPopover's update:modelValue).
on_editor_chipOption<EventHandler<Option<usize>>>NoneThe edited chip's writer (Vue: the local editorChip ref writes; None on close).
on_editor_tokenOption<EventHandler<String>>NoneThe edited token name's writer (Vue: the local editorToken writes).
on_editor_queryOption<EventHandler<String>>NoneThe editor search's writer (Vue: the local editorQuery writes).

Accessibility

  • The editable is a role="textbox" with aria-multiline="false"; the caption's for / id points at it, so the field is announced by name and a caption click focuses it.
  • While the vocabulary panel is open the editable publishes aria-haspopup="menu", aria-expanded and aria-owns (the out-of-flow popup rows become virtual descendants), and the highlighted row is exposed as aria-activedescendant — arrow keys are announced without moving DOM focus out of the field.
  • Chips are contenteditable="false" and the stored value serializes from each chip's data-raw, so voice input and IME composition edit around a chip instead of splitting it.
  • error renders as its own line under the box, and the box takes the error face; hint steps aside while an error shows.

Related components

  • HkTemplateText — the read-only rendering of the same template grammar.
  • HkTagInput — an ordered tag field with a searchable catalog.
  • HkMoneyInput — a currency amount over canonical decimal text.
  • HkTokenInput — a token budget with a unit picker.