Secret Field

Secret Field is a copy-paste React component that stops masked api key pasted as dots before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/secret-field
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsMasked API key pasted as dots

Was this component page useful?

How do I install Secret Field?

pnpm dlx shadcn@latest add @bollard/secret-field

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

How do I use Secret Field in React?

secret-field-usage.tsx
import { SecretField } from "@/components/ui/secret-field"

<SecretField label="Secret key" value="sk_live_51NcBollardUiExampleKey8f2a" />

What input mistakes does Secret Field catch?

  • Live versus test keys from the prefix (sk_live_, pk_test_…)
  • Masked text copied by hand, replaced with the real value on the clipboard
  • Revealed keys left on screen, re-masked after autoHide (default 10 s)
  • Tab switches while revealed, re-masked on visibilitychange

What props does Secret Field accept?

SecretField props
PropTypeDefault
value* (required)

The secret itself, e.g. an API key.

string—
label

Visible label.

string"API key"
revealable

Allow the user to reveal the full value.

booleantrue
revealed

Controlled reveal state.

boolean—
defaultRevealed

Initial reveal state when uncontrolled.

booleanfalse
onRevealedChange

Called when the value is revealed or re-masked.

(revealed: boolean) => void—
autoHide

Re-mask after this many ms. 0 disables. The value also re-masks when the tab is hidden.

number10_000
visibleTail

Trailing characters left visible while masked.

number4
revealLabel

Accessible names for the buttons and feedback.

string"Reveal"
hideLabel

Accessible label of the hide button.

string"Hide"
copyLabel

Accessible label of the copy button.

string"Copy"
copiedLabel

Announced after a successful copy.

string"Copied"
copyFailedLabel

Announced when copying fails.

string"Couldn't copy. Reveal and select it instead."
copiedMaskedLabel

Shown when someone copies the masked dots by hand and gets the real key instead.

string"Copied the full key, not the dots"
liveLabel

Pill text for live and test keys.

string"Live"
testLabel

Badge for a test-mode key.

string"Test"

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

How is Secret Field accessible?

  • Visible <label> on a read-only input; masked state exposed via aria-description "Hidden"
  • Reveal is an aria-pressed toggle with aria-controls and a changing aria-label
  • Copy button has an aria-label; copy result announced in a polite live region

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

What are the limitations and server boundaries?

This is a UX guard rail. Enforce on the server: Show full secrets only once at creation if you can, and support rotation and revocation server-side.

  • The full secret is still in the page's JavaScript and React props; masking is visual
  • Clipboard contents are outside its control once copied (clipboard managers, sync)
  • Prefix detection covers common formats only

What expensive mistakes does Secret Field stop?

Masked API key pasted as dots

Also known as

api key · secret input · reveal · copy key · stripe key · developer settings · password field · token

Field type

What dependencies does Secret Field require?

Secret Field facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameSecret Field
Registry identifier@bollard/secret-field
Install commandnpx shadcn@latest add @bollard/secret-field
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about Secret Field

What form validation mistake does Secret Field catch?

Secret Field prevents masked API key pasted as dots. Shows an API key masked but recognisable, re-hides it on a timer or when the tab is hidden, and copies the real value instead of dots. Catches: Live versus test keys from the prefix (sk_live_, pk_test_…), Masked text copied by hand, replaced with the real value on the clipboard, Revealed keys left on screen, re-masked after autoHide (default 10 s), Tab switches while revealed, re-masked on visibilitychange. Limitation: validate secret-field schemas on backend.

How do I install secret-field with shadcn?

Run `npx shadcn@latest add @bollard/secret-field`. Sources added: registry/default/secret-field/secret-field.tsx. Package requirements: lucide-react.

What props customize Secret Field?

Secret Field accepts `value`, `label`, `revealable`, `revealed`, `defaultRevealed`. Configures api key, secret input, reveal behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of secret-field?

The full secret is still in the page's JavaScript and React props; masking is visual. Clipboard contents are outside its control once copied (clipboard managers, sync). Prefix detection covers common formats only Server requirement: Show full secrets only once at creation if you can, and support rotation and revocation server-side.

How does Secret Field meet accessibility guidelines?

Visible <label> on a read-only input; masked state exposed via aria-description "Hidden". Reveal is an aria-pressed toggle with aria-controls and a changing aria-label. Copy button has an aria-label; copy result announced in a polite live region. Minimizes errors: copied masked api key, api key visible on screen.

Which components pair with Secret Field?