Skip to content

Secret Field

A read-only API key or token, masked to its prefix and last 4 characters. Reveal it by press and hold or with a toggle, copy it without showing it, and the mask comes back on its own.

On this page
Used for
  • API keys on a settings page
  • Webhook signing secrets
  • The one-time view of a new key
  • Tokens in a connect-your-agent flow

Examples

Reveal
Size

Without a prefix

Installation

npx knowns-ui@latest add secret-field
For Claude Code, Cursor or Codex: installs it and wires the props to your own data.

Props

value
string
The secret. Rendered only while revealed. Or leave it out and pass parts and load.
parts / load
{ head, tail } / (signal) => Promise<string | null>
Fetch the secret on demand: the mask shows parts (your stored prefix and last 4), a reveal or copy calls load, and the key is forgotten when masked. null says it can't be shown again; the signal aborts when a hold ends first.
label / aria-labelledby
string / string
The field's name for screen readers, or the id of your visible label.
revealMode
"hold" | "toggle"
Default"hold"
Hold: shown while the eye is pressed. Toggle: the eye shows and hides it.
revealTimeout
number | null
Default10000
Toggle mode: ms before the mask comes back. 0 or null keeps it until hidden by hand.
revealed / onRevealedChange
boolean / (revealed, cause) => void
Control the reveal. The cause is hold, toggle, release, copy, timeout, blur or hidden.
onReveal
(cause: "hold" | "toggle") => void
Called each time the key is shown, for an audit log.
onCopy
() => void
Called after the key is on the clipboard.
prefix
"auto" | number | string
Default"auto"
What stays at the start: a type prefix like kn_live_, a number of characters, or a literal prefix.
visibleEnd
number
Default4
Characters that stay at the end. A short secret hides everything.
copyable / copiedLabel
boolean / string
Defaulttrue / "Copied"
Show the copy button, and what is announced after a copy.
actions
ReactNode
Controls at the end of the field, e.g. a Rotate button.
size
"sm" | "md" | "lg"
Default"md"
28, 32 or 36px high, the same as Input; taller on touch screens.
disabled
boolean
Defaultfalse
Masked, with the buttons off.
partsrequired
{ head, tail }
The mask on its own, the same glyphs and spoken label as the field, at the size of the text around it. For lists that show a key but never reveal it, as the API keys settings rows do.

Accessibility

  • The field is a labelled group. Masked, a screen reader hears only the kept parts ("kn_live key, hidden, ends in 3 8 f 2"), never the secret, which is not in the DOM.
  • The eye shows the action, not the state: an open eye while masked, eye-off while revealed. Its name follows it: "Hold to reveal" or "Reveal" while masked, "Release to hide" or "Hide" while revealed. In hold mode, hold Space or Enter; a screen reader's click, which has no hold, reveals it like a toggle with the 10 second timeout.
  • Copy is a named button; "Copied" is announced in a polite live region, and a blocked clipboard is announced with what to do instead.
  • Revealed, the key is selectable text that keeps focus inside the field, so selecting it by hand does not hide it. A key longer than the field scrolls inside it with a soft fade at the edges, and starts scrolled to the end so the last characters show.
  • Buttons are 32px or larger on a touch screen.

What it handles

  1. 01Masks the key to its type prefix and last 4 characters with a fixed run of dots, so the mask never tells how long the key is, and keeps the secret out of the DOM until it is revealed.
  2. 02Reveals by press and hold (hidden again on release) or by a toggle that hides again after 10 seconds, with a hairline that drains on the same clock.
  3. 03Copies the whole key without showing it, announces Copied, and puts the mask back if it was showing.
  4. 04Puts the mask back when focus leaves the field, when the tab is hidden and when the window loses focus.
  5. 05Calls onReveal each time the key is shown, with hold or toggle, so your server can write an audit entry.
  6. 06Takes a Rotate button or a menu at the end, and lines up with Input at 28, 32 and 36px.

States

First render
Masked; nothing plays
none
Reveal or hide
The text turns: it fades up from 35% with a 2px blur that is gone as it lands; the eye turns into eye-off (the action is now hide) and back
180ms ease out
Toggled reveal
A hairline under the key drains from full to empty, then the mask comes back
10s linear (revealTimeout)
Copy
The copy icon becomes a check that pops in, for 1.6s; the mask comes back
180ms spring
Focus leaves, tab hidden, window blur
Masked at once
instant
Reduced motion
Every change is instant; the drain hairline is not drawn and the timeout still hides it
0ms

Works with

When to use

When to use

  • API keys, signing secrets and tokens on a settings page: masked to the prefix and last 4, revealed by hold or toggle, copied without showing.

When not to use

Using with AI

Use Copy page for AI above to give your assistant this page, Copy prompt under the install command to have it installed and wired to your data, or connect the Knowns UI MCP server and just ask:

  • Add the Knowns UI Secret Field to my app and wire it to my own data.
  • I need aPI keys, signing secrets and tokens on a settings page: masked to the prefix and last 4, revealed by hold or toggle, copied without showing. Set that up with the Knowns UI Secret Field.
  • Which Secret Field props do I need for a minimal setup? Show me a short example.

With the server connected, your assistant calls get_component({ name: "secret-field" }) and search_docs({ query: "secret field" }).

Need help?

Stuck on Secret Field, or found something off? We read every message.