Components
Token Field
Text input with inline chip tokens and tags for AI prompt engineering, hashtag entry, and mention tagging.
The TokenField component provides an editable text area where inline items can be converted into interactive token chips. Ideal for AI prompt interfaces, @mention tagging, and #hashtag inputs, it balances text typing with structured token manipulation and keyboard deletion.
AI Prompt Template & TokensType text or use interactive tokens with backspace deletion.
Translate portal design into @PersianStyle with @TurquoiseAccent
Serialized: Translate portal design into @PersianStyle with @TurquoiseAccent
Import
import { TokenField, TokenFieldInput, TokenFieldToken } from "@hashti/react";
Anatomy & Compound Composition
// Convenience component with automatic label and description
<TokenField
label="AI Prompt Templates & Tags"
placeholder="Type a prompt or insert {{token}}..."
/>
// Or compound composition
<TokenField.Root>
<TokenField.Label>Prompt Variables</TokenField.Label>
<TokenField.Input placeholder="Add token...">
{(segment) => (
<TokenField.Token>
{segment.text}
</TokenField.Token>
)}
</TokenField.Input>
<TokenField.Description>Press Enter or comma to create a token.</TokenField.Description>
</TokenField.Root>
Examples
AI Prompt Construction with Variable Tokens
In modern AI engineering applications, developers need to combine natural language instructions with dynamic slot parameters:
import { useState } from "react";
import { TokenField } from "@hashti/react";
export function AIPromptTokenFieldDemo() {
const [value, setValue] = useState("");
return (
<div className="max-w-md space-y-3">
<TokenField
label="System Prompt Template"
placeholder="e.g. Translate the following text into {{target_language}}..."
description="Insert variable tokens enclosed in double braces."
value={value}
onChange={setValue}
multiline
size="md"
/>
<div className="flex gap-2">
<button
type="button"
onClick={() => setValue((prev) => prev + " {{user_query}} ")}
className="text-xs bg-gray-100 dark:bg-gray-800 px-2.5 py-1 rounded-md hover:bg-gray-200"
>
+ Insert user_query
</button>
<button
type="button"
onClick={() => setValue((prev) => prev + " {{temperature}} ")}
className="text-xs bg-gray-100 dark:bg-gray-800 px-2.5 py-1 rounded-md hover:bg-gray-200"
>
+ Insert temperature
</button>
</div>
</div>
);
}
Multi-line Token Input with Validation States
TokenField integrates with Hashti’s standard field presentation props, including validation error messages and helper descriptions:
import { TokenField } from "@hashti/react";
export function ValidatedTokenFieldDemo() {
return (
<div className="max-w-md space-y-4">
<TokenField
label="Required Architectural Attributes"
placeholder="Enter attributes..."
isInvalid
errorMessage="At least one architectural threshold attribute must be specified."
multiline
/>
</div>
);
}
Props Reference
TokenField (Convenience)
| Prop | Type | Default | Description |
|---|---|---|---|
label | ReactNode | undefined | Field label displayed above input. |
placeholder | string | undefined | Input placeholder text when empty. |
description | ReactNode | undefined | Helpful caption text rendered beneath field. |
errorMessage | ReactNode | undefined | Validation error message displayed when isInvalid is true. |
size | "sm" | "md" | "lg" | "md" | Field size preset. |
multiline | boolean | false | Whether the input allows multiple lines of text with expanding height. |
allowsNewlines | boolean | true | When multiline is true, whether Shift+Enter or Enter inserts a newline. |
isReadOnly | boolean | false | Whether text and tokens are read-only. |
isDisabled | boolean | false | Whether input is completely disabled. |
Accessibility & Keyboard Navigation
- Token Deletion: When cursor is placed immediately after a token, pressing
Backspaceselects the token; pressingBackspaceagain removes it. - Arrow Navigation: Left and Right arrows skip smoothly past token boundaries as atomic units.
- Copy & Paste: Selecting a range of text containing tokens copies both raw text and token identifiers cleanly to the system clipboard.
Keyboard Interactions
| Key | Action |
|---|---|
| Backspace | Deletes character or removes preceding token chip. |
| Arrow Left / Arrow Right | Traverses cursor across text and token boundaries. |
| Enter | Commits token creation from input suggestion. |
WAI-ARIA & Data Attributes
| Attribute | Target | Description |
|---|---|---|
[data-hovered] | Token Chip | Present on pointer hover over chip. |
[data-focused] | Token Chip, Input | Present when receiving focus. |
[data-selected] | Token Chip | Set when token chip is highlighted for deletion. |