Code Input

A code field that turns off autocorrect and catches smart quotes, long dashes and hidden characters, so pasted commands and JSON don't fail invisibly.

StopsSmart quotes break a pasted command

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/code-input.json

The files land in your project. They're yours to edit.

Usage

code-input-usage.tsx
import { CodeInput } from "@/components/ui/code-input"

<CodeInput
  label="Deploy command (pasted from a doc)"
  rows={4}
  defaultValue={"git push —force origin main\nexport API_KEY=“sk_live_51H\u200b8xQ”"}
/>

What it catches

  • Curly quotes that break shell commands and JSON
  • En/em dashes where -- or - was meant (—force → --force)
  • Ellipsis characters and invisible characters
  • Invalid JSON, with the parse error (json prop)

Props

CodeInput props
PropTypeDefault
label

Visible label.

string"Command"
hint

Helper text shown under the field while there is nothing to warn about.

string—
value

Controlled contents.

string—
defaultValue

Initial contents when uncontrolled.

string""
onValueChange

Called on every edit, including the one-tap fix.

(value: string) => void—
json

Validate the contents as JSON and point at the line and column of the error.

booleanfalse
validJsonMessage

Text shown when the JSON parses. Same as `messages.validJson`.

string—
messages

Reword or translate any message.

Partial<typeof CODE_INPUT_MESSAGES>—

* required. Also accepts the native props of <textarea> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; aria-invalid and aria-describedby to an aria-live="polite" hint
  • Each issue lists its line and column in text
  • Fix button has visible text

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Fixes are character substitutions; it doesn't check that the command or config is right
  • Intentional typographic characters inside strings may be flagged

What it stops

Smart quotes break a pasted command

Also known as

code input · command · terminal · json · smart quotes · autocorrect off · api key · snippet

Field type

Dependencies

Pairs well with