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-fieldFor Claude Code, Cursor or Codex: installs it and wires the props to your own data.
Paste this into your coding agent (Claude Code, Cursor, Codex). It checks your project, sets up the registry, runs the install and verifies it.
Install prompt
Install Secret field from Knowns UI into this project. Work step by step, show me each change, and ask before you edit files outside this project.
Context: Knowns UI (https://ui.knowns.dev) is a shadcn registry. Items land in the project as source files. Docs: https://ui.knowns.dev/docs/secret-field
1. Check the project first. Stop and tell me if any of these is missing:
- React 19 and Tailwind CSS v4.
- A components.json at the project root. If there is none, ask me before running `npx knowns-ui@latest init --no-key` (it runs shadcn init when needed, then adds the registries).
2. Run:
```bash
npx knowns-ui@latest add secret-field
```
It writes these files:
- lib/knowns/run.ts
- lib/knowns/json.tsx
- lib/knowns/status.ts
- lib/knowns/tone.ts
- lib/knowns/types.ts
- lib/knowns/use-abortable.ts
- lib/knowns/utils.ts
- components/ui/knowns/field-class.ts
- lib/knowns/motion.tsx
- lib/knowns/motion-utils.ts
- components/ui/knowns/secret-field/secret-field.tsx
- components/ui/knowns/secret-field/secret-field-utils.ts
and installs these npm packages: clsx@^2.1.1, tailwind-merge@^3.7.0.
3. While it runs:
- It also adds a few @keyframes (all named kn-*) to the global CSS file (globals.css or the file components.json points at). Let it: they only add animations.
- If it asks to overwrite files under lib/knowns/: these are shared by every Knowns UI item. List them, say whether I changed them (check git), and ask me before you answer.
- If it asks to overwrite any other file, show me the diff and ask me.
4. Verify:
- Every file in the list above exists.
- The project type-checks (for example `npx tsc --noEmit`) and the dev build has no new errors.
5. Use it: follow the examples and props on https://ui.knowns.dev/docs/secret-field, and ask me if anything about my data is unclear.
If the Knowns UI MCP server is connected (https://ui.knowns.dev/docs/ai-and-mcp), use get_component({ name: "secret-field" }) or search_docs for details.
Finish with a short summary: the files you added or changed, the packages you installed, and anything I still need to do.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- Default
10000 - 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- Default
4 - Characters that stay at the end. A short secret hides everything.
- copyable / copiedLabel
boolean / string- Default
true / "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- Default
false - Masked, with the buttons off.
| Prop | Type | Default | Description |
|---|---|---|---|
| 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" | "hold" | Hold: shown while the eye is pressed. Toggle: the eye shows and hides it. |
| revealTimeout | number | null | 10000 | 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 | "auto" | What stays at the start: a type prefix like kn_live_, a number of characters, or a literal prefix. |
| visibleEnd | number | 4 | Characters that stay at the end. A short secret hides everything. |
| copyable / copiedLabel | boolean / string | true / "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" | "md" | 28, 32 or 36px high, the same as Input; taller on touch screens. |
| disabled | boolean | false | 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.
| Prop | Type | Default | Description |
|---|---|---|---|
| partsrequired | { head, tail } | required | 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
- 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.
- 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.
- 03Copies the whole key without showing it, announces Copied, and puts the mask back if it was showing.
- 04Puts the mask back when focus leaves the field, when the tab is hidden and when the window loses focus.
- 05Calls onReveal each time the key is shown, with hold or toggle, so your server can write an audit entry.
- 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
| State | What moves | Timing |
|---|---|---|
| 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
- A password the person types: use Password Field.
- A code snippet that contains a key: use Code Block.
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" }).