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.
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.
Hi {{ email }}, your key is {{ md5_email }}.
Type {{ to pick a placeholder.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import{ref,typeCSSProperties}from"vue";import{HkTemplateField,typeHkTemplateTokenDef}from"@celestia-island/hikari";consttokens: HkTemplateTokenDef[]=[{name:"email",label:"Email",description:"The address the message goes to"},{name:"md5_email",label:"Email hash",description:"Lower-case MD5 of the address"},{name:"base",label:"Base URL",description:"The site's public origin",group:"url"},{name:"lang",label:"Locale",description:"Two-letter language tag",group:"url"},];constcolumn: CSSProperties={display:"grid",gap:"16px",maxWidth:"26rem"};consttemplate=ref("Hi {{email}}, your key is {{ md5_email }}.");exportdefault()=>(<divstyle={column}><HkTemplateFieldmodelValue={template.value}onUpdate:modelValue={(v:string) => {
template.value = v;
}}
tokens={tokens}label="Greeting template"hint="Type {{ to pick a placeholder."/></div>
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
let tokens =vec![
TemplateTokenDef { name:"email".to_string(), label:Some("Email".to_string()), description:Some("The address the message goes to".to_string()), group:None},
TemplateTokenDef { name:"md5_email".to_string(), label:Some("Email hash".to_string()), description:Some("Lower-case MD5 of the address".to_string()), group:None},
TemplateTokenDef { name:"base".to_string(), label:Some("Base URL".to_string()), description:Some("The site's public origin".to_string()), group:Some("url".to_string())},
TemplateTokenDef { name:"lang".to_string(), label:Some("Locale".to_string()), description:Some("Two-letter language tag".to_string()), group:Some("url".to_string())},];rsx!{
div { style:"display:grid;gap:16px;max-width:26rem",
TemplateField {
model_value:"Hi {{email}}, your key is {{ md5_email }}.".to_string(),
tokens: tokens,
label:Some("Greeting template".to_string()),
hint:Some("Type {{ to pick a placeholder.".to_string()),
id:Some("greeting".to_string()),}}}
import { ref, type CSSProperties } from "vue";
import { HkTemplateField, type HkTemplateTokenDef } from "@celestia-island/hikari";
const tokens: HkTemplateTokenDef[] = [
{ name: "email", label: "Email", description: "The address the message goes to" },
{ name: "md5_email", label: "Email hash", description: "Lower-case MD5 of the address" },
{ name: "base", label: "Base URL", description: "The site's public origin", group: "url" },
{ name: "lang", label: "Locale", description: "Two-letter language tag", group: "url" },
];
const column: CSSProperties = { display: "grid", gap: "16px", maxWidth: "26rem" };
const template = ref("Hi {{email}}, your key is {{ md5_email }}.");
export default () => (
<div style={column}>
<HkTemplateField
modelValue={template.value}
onUpdate:modelValue={(v: string) => {
template.value = v;
}}
tokens={tokens}
label="Greeting template"
hint="Type {{ to pick a placeholder."
/>
</div>
);
let tokens = vec![
TemplateTokenDef { name: "email".to_string(), label: Some("Email".to_string()), description: Some("The address the message goes to".to_string()), group: None },
TemplateTokenDef { name: "md5_email".to_string(), label: Some("Email hash".to_string()), description: Some("Lower-case MD5 of the address".to_string()), group: None },
TemplateTokenDef { name: "base".to_string(), label: Some("Base URL".to_string()), description: Some("The site's public origin".to_string()), group: Some("url".to_string()) },
TemplateTokenDef { name: "lang".to_string(), label: Some("Locale".to_string()), description: Some("Two-letter language tag".to_string()), group: Some("url".to_string()) },
];
rsx! {
div { style: "display:grid;gap:16px;max-width:26rem",
TemplateField {
model_value: "Hi {{email}}, your key is {{ md5_email }}.".to_string(),
tokens: tokens,
label: Some("Greeting template".to_string()),
hint: Some("Type {{ to pick a placeholder.".to_string()),
id: Some("greeting".to_string()),
}
}
}
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.
{{ base }}/{{ lang }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import{typeCSSProperties}from"vue";import{HkTemplateField,typeHkTemplateTokenDef}from"@celestia-island/hikari";consttokens: HkTemplateTokenDef[]=[{name:"email",label:"Email",description:"The address the message goes to",group:"contact"},{name:"phone",label:"Phone",description:"E.164 number",group:"contact"},{name:"base",label:"Base URL",description:"The site's public origin",group:"url"},{name:"lang",label:"Locale",description:"Two-letter language tag",group:"url"},];constheadings: Record<string,string>={contact:"Contact details",url:"Web address"};constcolumn: CSSProperties={maxWidth:"26rem"};exportdefault()=>(<divstyle={column}><HkTemplateFieldmodelValue="{{ base }}/{{ lang }}"tokens={tokens}groupLabel={(group:string) => headings[group] ?? group}label="Public link"/></div>
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
letheadings=|group:&str|match group {"contact"=>"Contact details".to_string(),"url"=>"Web address".to_string(),
other => other.to_string(),};rsx!{
div { style:"max-width:26rem",
TemplateField {
model_value:"{{ base }}/{{ lang }}".to_string(),
tokens:vec![
TemplateTokenDef { name:"email".to_string(), label:Some("Email".to_string()), description:Some("The address the message goes to".to_string()), group:Some("contact".to_string())},
TemplateTokenDef { name:"phone".to_string(), label:Some("Phone".to_string()), description:Some("E.164 number".to_string()), group:Some("contact".to_string())},
TemplateTokenDef { name:"base".to_string(), label:Some("Base URL".to_string()), description:Some("The site's public origin".to_string()), group:Some("url".to_string())},
TemplateTokenDef { name:"lang".to_string(), label:Some("Locale".to_string()), description:Some("Two-letter language tag".to_string()), group:Some("url".to_string())},],
group_label:Some(std::rc::Rc::new(headings)),
label:Some("Public link".to_string()),
id:Some("public-link".to_string()),}}}
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
/posts/{{ slug }}
Literal text stays as typed.
/posts/{{ slug
A placeholder is not closed
/posts/{{ id }}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import{typeCSSProperties}from"vue";import{HkTemplateField,typeHkTemplateTokenDef}from"@celestia-island/hikari";consttokens: HkTemplateTokenDef[]=[{name:"slug",label:"Slug",description:"URL-safe name"},{name:"id",label:"Id",description:"Numeric identifier"},];constcolumn: CSSProperties={display:"grid",gap:"16px",maxWidth:"26rem"};exportdefault()=>(<divstyle={column}><HkTemplateFieldmodelValue="/posts/{{ slug }}"tokens={tokens}label="Path"hint="Literal text stays as typed."/><HkTemplateFieldmodelValue="/posts/{{ slug "tokens={tokens}label="Path"error="A placeholder is not closed"/><HkTemplateFieldmodelValue="/posts/{{ id }}"tokens={tokens}label="Path"disabledplaceholder="/posts/{{ slug }}"/></div>
);
The raw {{ token }} value, verbatim from storage (Vue modelValue, default "").
tokens
Vec<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).
label
Option<String>
None
Field caption; points the label at the editable (label clicks focus, screen readers announce the field by name).
hint
Option<String>
None
Muted helper line under the field (hidden while an error shows).
error
Option<String>
None
Error line + the box's error face (an EMPTY string is no error, exactly Vue's truthiness).
placeholder
String
String::new()
The :empty placeholder of the editable (Vue placeholder, default "").
disabled
bool
false
—
submit_on_enter
Option<EventHandler<()>>
None
Submit intent on Enter (when no suggestion row is active) — the same contract as Input.
group_label
Option<Rc<dyn Fn(&str) -> String>>
None
Maps a token's group key to the heading label shown over its run (Vue: the groupLabel FUNCTION prop).
id
Option<String>
None
Element id of the editable (Vue generates one with useId); also seeds the panel-rows / row ids.
panel_anchor
Option<PopoverAnchorRect>
None
The 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_offset
f64
6.0
Gap between the field and the vocabulary panel (Vue: HkMenu's offset default 6).
suggest_open
bool
false
Vocabulary panel visibility (Vue: suggestOpen).
suggest_query
String
String::new()
The typed identifier inside the live {{ query trigger (Vue: suggestQuery) — the panel's filter input.
suggest_active
i32
0
The panel's keyboard cursor: an index into the FILTERED rows (Vue: suggestActive).
trigger
Option<TemplateFieldTrigger>
None
The live trigger's serialized span (Vue: triggerRange) — what a pick replaces.
editor_open
bool
false
Chip editor visibility (Vue: editorOpen).
editor_chip
Option<usize>
None
The chip the editor edits, by token-segment index (Vue holds the DOM element).
editor_token
String
String::new()
The token name the editor shows (Vue: editorToken).
editor_query
String
String::new()
The editor's search query (Vue: editorQuery).
onupdate_model_value
Option<EventHandler<String>>
None
Vue: update:modelValue — the full next value.
oncaret
Option<EventHandler<usize>>
None
The 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_input
Option<EventHandler<InputEvent>>
None
The 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_change
Option<EventHandler<bool>>
None
Fires with the desired panel state (Vue: HkMenu's update:open).
on_suggest_active
Option<EventHandler<i32>>
None
The keyboard cursor's writer (Vue: the local suggestActive writes).
on_editor_open_change
Option<EventHandler<bool>>
None
Fires with the desired editor state (Vue: HPopover's update:modelValue).
on_editor_chip
Option<EventHandler<Option<usize>>>
None
The edited chip's writer (Vue: the local editorChip ref writes; None on close).
on_editor_token
Option<EventHandler<String>>
None
The edited token name's writer (Vue: the local editorToken writes).
on_editor_query
Option<EventHandler<String>>
None
The 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.