Skip to Content
Hashti Design System
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)

PropTypeDefaultDescription
labelReactNodeundefinedField label displayed above input.
placeholderstringundefinedInput placeholder text when empty.
descriptionReactNodeundefinedHelpful caption text rendered beneath field.
errorMessageReactNodeundefinedValidation error message displayed when isInvalid is true.
size"sm" | "md" | "lg""md"Field size preset.
multilinebooleanfalseWhether the input allows multiple lines of text with expanding height.
allowsNewlinesbooleantrueWhen multiline is true, whether Shift+Enter or Enter inserts a newline.
isReadOnlybooleanfalseWhether text and tokens are read-only.
isDisabledbooleanfalseWhether input is completely disabled.

Accessibility & Keyboard Navigation

  • Token Deletion: When cursor is placed immediately after a token, pressing Backspace selects the token; pressing Backspace again 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

KeyAction
BackspaceDeletes character or removes preceding token chip.
Arrow Left / Arrow RightTraverses cursor across text and token boundaries.
EnterCommits token creation from input suggestion.

WAI-ARIA & Data Attributes

AttributeTargetDescription
[data-hovered]Token ChipPresent on pointer hover over chip.
[data-focused]Token Chip, InputPresent when receiving focus.
[data-selected]Token ChipSet when token chip is highlighted for deletion.