Focus Frame
The field tells you exactly where you are.
Your preview settings
{
"validate": "blur",
"simulateError": false
}These are the exact settings driving this demo, including sample content and simulated states. For the installable component’s public API, see Usage and Props below.
Clear the email to see an error, then save. The message slot never pushes the form.
A real browser viewport. Scroll within the preview when the sample needs more space. Configuration stays in sync between sizes.
01What it does
A labelled form field where focus draws a precise frame around the input, the label warms, and hint, error and success messages crossfade in a reserved slot. Validation uses icons and text as well as colour.
In this previewA workspace profile form with a live required name, a validated email, an optional description, a read-only id and a disabled billing contact. Save can succeed or fail from the preview controls, and reset restores the saved values.
Design decisions
The label lives outside the input. Floating-label patterns hide context as soon as typing begins; this field keeps it visible and uses the frame for focus instead.
The message row has a fixed minimum height, so moving from a hint to a two-line error cannot shift the rest of the form.
The focus frame uses a restrained outer ring plus four tiny corner marks. The effect is legible at a glance but does not compete with the value being typed.
02Install
Registry install
Run this in a React project with components.json. The component and its stylesheet land in components/lab/focus-frame/.
npx shadcn@latest add https://lab.tanishk.me/r/focus-frame.jsonFiles included
2- components/lab/focus-frame/focus-frame.tsxcomponent
- components/lab/focus-frame/focus-frame.cssstyles
Manual install: copy each file into the same folder and preserve its relative imports. Open the source
03Usage
"use client";
import { useState } from "react";
import { FocusFrame } from "@/components/lab/focus-frame/focus-frame";
export function ProfileField() {
const [name, setName] = useState("");
const [error, setError] = useState("");
return (
<FocusFrame
label="Workspace name"
value={name}
onChange={setName}
onBlur={() => setError(name.trim() ? "" : "A name is required.")}
error={error}
hint="Shown to everyone with access."
maxLength={60}
showCount
required
/>
);
}04Props
| Prop | Type | Default | Notes |
|---|---|---|---|
label | string | — | Visible and accessible field label; never replaced by a placeholder. |
value | string | — | Controlled field value. |
onChange | (value: string) => void | — | Receives every edit. |
onBlur | () => void | — | Hook for host validation timing. |
id | string | — | Field id; generated when omitted. |
name | string | — | Native form field name. |
type | "text" | "email" | "password" | "url" | "text" | Native input type when not multiline. |
placeholder | string | — | Optional example, never the only label. |
hint | string | — | Quiet helper message. |
error | string | — | Error message; also sets aria-invalid and the error treatment. |
success | string | — | Optional restrained success message. |
required | boolean | false | Marks the field required and shows an asterisk. |
disabled | boolean | false | Native disabled with a muted, dashed frame. |
readOnly | boolean | false | Native read-only with a tinted frame and a visible flag. |
multiline | boolean | false | Render a textarea instead of an input. |
rows | number | 4 | Visible rows for a multiline field. |
maxLength | number | — | Native maximum length. |
showCount | boolean | false | Show the character count when maxLength is present. |
autoComplete | string | — | Native autocomplete hint. |
size | "compact" | "regular" | "regular" | Field height and type scale. |
className | string | — | Forwarded to the field root. |
05Accessibility
- A real <label> is always visible above the control; placeholder text is optional and never the label.
- Errors set aria-invalid and are linked through aria-describedby; the message also carries an icon and text, so colour is not the only signal.
- The message area reserves its space and crossfades content, so validation never moves the next field under the pointer.
- Disabled and read-only are native attributes with distinct visual treatments and explicit flags.
- The message region is polite and atomic; success is a short confirmation rather than a second form event.
06Source
2 files, 484 lines. The combined copy is a reference; save each file separately for use.
components/lab/focus-frame/focus-frame.tsx— press enter to show or hide the source
"use client";
import { useId, type ChangeEvent } from "react";
import "./focus-frame.css";
export type FocusFrameProps = {
label: string;
value: string;
onChange: (value: string) => void;
onBlur?: () => void;
id?: string;
name?: string;
type?: "text" | "email" | "password" | "url";
placeholder?: string;
hint?: string;
error?: string;
success?: string;
required?: boolean;
disabled?: boolean;
readOnly?: boolean;
multiline?: boolean;
rows?: number;
maxLength?: number;
showCount?: boolean;
autoComplete?: string;
size?: "compact" | "regular";
className?: string;
};
/**
* FOCUS FRAME
*
* A labelled field where the frame is the interaction: a quiet border
* resolves into a precise accent, the label warms, and the message slot
* fades between hint, error and success without moving the page. The
* label lives outside the input, so it is never replaced by placeholder
* text. Errors carry an icon and a message as well as a border colour.
*/
export function FocusFrame({
label,
value,
onChange,
onBlur,
id,
name,
type = "text",
placeholder,
hint,
error,
success,
required,
disabled,
readOnly,
multiline,
rows = 4,
maxLength,
showCount,
autoComplete,
size = "regular",
className,
}: FocusFrameProps) {
const generated = useId();
const fieldId = id ?? `${generated}-field`;
const messageId = `${fieldId}-message`;
const message = error ?? success ?? hint ?? "";
const tone = error ? "error" : success ? "success" : hint ? "hint" : "none";
const describedBy = message ? messageId : undefined;
const change = (
event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
) => onChange(event.target.value);
return (
<div
className={`ff-root${className ? ` ${className}` : ""}`}
data-size={size}
data-tone={tone}
data-disabled={disabled ? "true" : "false"}
data-readonly={readOnly ? "true" : "false"}
data-filled={value.length > 0 ? "true" : "false"}
>
<div className="ff-label-row">
<label htmlFor={fieldId} className="ff-label">
{label}
{required ? (
<span className="ff-required" aria-hidden="true">
*
</span>
) : null}
</label>
{readOnly ? <span className="ff-flag">Read only</span> : null}
{disabled ? <span className="ff-flag">Disabled</span> : null}
</div>
<div className="ff-frame">
<span className="ff-corner ff-corner--tl" aria-hidden="true" />
<span className="ff-corner ff-corner--tr" aria-hidden="true" />
<span className="ff-corner ff-corner--bl" aria-hidden="true" />
<span className="ff-corner ff-corner--br" aria-hidden="true" />
{multiline ? (
<textarea
id={fieldId}
name={name}
className="ff-input"
value={value}
rows={rows}
placeholder={placeholder}
required={required}
disabled={disabled}
readOnly={readOnly}
maxLength={maxLength}
aria-invalid={error ? true : undefined}
aria-describedby={describedBy}
onChange={change}
onBlur={onBlur}
/>
) : (
<input
id={fieldId}
name={name}
className="ff-input"
type={type}
value={value}
placeholder={placeholder}
required={required}
disabled={disabled}
readOnly={readOnly}
maxLength={maxLength}
autoComplete={autoComplete}
aria-invalid={error ? true : undefined}
aria-describedby={describedBy}
onChange={change}
onBlur={onBlur}
/>
)}
</div>
<div className="ff-message-row">
<div
className="ff-message"
id={messageId}
aria-live="polite"
aria-atomic="true"
>
{message ? (
<span key={message}>
{error ? (
<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
<circle
cx="8"
cy="8"
r="6.2"
fill="none"
stroke="currentColor"
strokeWidth="1.3"
/>
<path
d="M8 4.8v4.1M8 11.2v.4"
stroke="currentColor"
strokeWidth="1.4"
strokeLinecap="round"
/>
</svg>
) : success ? (
<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
<path
d="M3 8.3l3.2 3.1L13 4.7"
fill="none"
stroke="currentColor"
strokeWidth="1.6"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
) : null}
{message}
</span>
) : null}
</div>
{showCount && maxLength ? (
<span className="ff-count" aria-hidden="true">
{value.length}/{maxLength}
</span>
) : null}
</div>
</div>
);
}components/lab/focus-frame/focus-frame.css— press enter to show or hide the source
.ff-root {
--ff-ink: #20242b;
--ff-muted: #6b7079;
--ff-line: rgba(32, 36, 43, 0.16);
--ff-surface: #ffffff;
--ff-soft: #f6f7f8;
--ff-accent: #2d5bd1;
--ff-accent-soft: rgba(45, 91, 209, 0.08);
--ff-error: #a52a24;
--ff-ok: #1d6b47;
--ff-focus: #2d5bd1;
--ff-ease: cubic-bezier(0.22, 1, 0.36, 1);
display: grid;
gap: 7px;
min-width: 0;
color: var(--ff-ink);
font: inherit;
}
.ff-label-row {
display: flex;
align-items: baseline;
justify-content: space-between;
gap: 12px;
min-width: 0;
}
.ff-label {
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: -0.004em;
line-height: 1.35;
color: var(--ff-ink);
transition: color 160ms var(--ff-ease);
}
.ff-root:focus-within .ff-label {
color: var(--ff-accent);
}
.ff-root[data-tone="error"] .ff-label {
color: var(--ff-error);
}
.ff-required {
margin-left: 3px;
color: var(--ff-error);
}
.ff-flag {
color: var(--ff-muted);
font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
font-size: 0.5625rem;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.ff-frame {
position: relative;
min-width: 0;
border: 1px solid var(--ff-line);
border-radius: 9px;
background: var(--ff-surface);
transition:
border-color 170ms var(--ff-ease),
box-shadow 200ms var(--ff-ease),
background-color 170ms var(--ff-ease);
}
.ff-frame::after {
content: "";
position: absolute;
inset: -3px;
border-radius: 12px;
border: 1px solid var(--ff-accent);
opacity: 0;
transform: scale(0.992);
pointer-events: none;
transition:
opacity 180ms var(--ff-ease),
transform 200ms var(--ff-ease);
}
.ff-frame:hover {
border-color: rgba(32, 36, 43, 0.3);
}
.ff-root:focus-within .ff-frame {
border-color: var(--ff-accent);
box-shadow: 0 0 0 3px var(--ff-accent-soft);
}
.ff-root:focus-within .ff-frame::after {
opacity: 1;
transform: scale(1);
}
.ff-root[data-tone="error"] .ff-frame {
border-color: var(--ff-error);
box-shadow: 0 0 0 3px rgba(165, 42, 36, 0.08);
}
.ff-root[data-tone="error"]:focus-within .ff-frame {
border-color: var(--ff-error);
}
.ff-root[data-tone="success"] .ff-frame {
border-color: color-mix(in srgb, var(--ff-ok) 50%, var(--ff-line));
}
.ff-input {
display: block;
width: 100%;
min-height: 40px;
margin: 0;
padding: 9px 11px;
border: 0;
border-radius: 8px;
background: transparent;
color: inherit;
font: inherit;
font-size: 0.875rem;
line-height: 1.45;
outline: none;
resize: vertical;
}
.ff-root[data-size="compact"] .ff-input {
min-height: 34px;
padding: 6px 10px;
font-size: 0.8125rem;
}
textarea.ff-input {
min-height: 92px;
}
.ff-input::placeholder {
color: color-mix(in srgb, var(--ff-muted) 62%, transparent);
}
.ff-input:focus {
outline: none;
}
.ff-input:disabled {
color: var(--ff-muted);
cursor: not-allowed;
}
.ff-root[data-disabled="true"] .ff-frame {
border-style: dashed;
background: var(--ff-soft);
}
.ff-root[data-disabled="true"] .ff-label {
color: var(--ff-muted);
}
.ff-root[data-readonly="true"] .ff-frame {
background: var(--ff-soft);
}
.ff-root[data-readonly="true"] .ff-input {
cursor: default;
}
.ff-corner {
position: absolute;
width: 5px;
height: 5px;
border-color: var(--ff-accent);
border-style: solid;
opacity: 0;
pointer-events: none;
transition:
opacity 160ms var(--ff-ease),
transform 190ms var(--ff-ease);
}
.ff-root[data-tone="error"] .ff-corner {
border-color: var(--ff-error);
}
.ff-corner--tl {
top: -1px;
left: -1px;
border-width: 1.5px 0 0 1.5px;
border-top-left-radius: 9px;
transform: translate(2px, 2px);
}
.ff-corner--tr {
top: -1px;
right: -1px;
border-width: 1.5px 1.5px 0 0;
border-top-right-radius: 9px;
transform: translate(-2px, 2px);
}
.ff-corner--bl {
bottom: -1px;
left: -1px;
border-width: 0 0 1.5px 1.5px;
border-bottom-left-radius: 9px;
transform: translate(2px, -2px);
}
.ff-corner--br {
right: -1px;
bottom: -1px;
border-width: 0 1.5px 1.5px 0;
border-bottom-right-radius: 9px;
transform: translate(-2px, -2px);
}
.ff-root:focus-within .ff-corner {
opacity: 1;
transform: translate(0, 0);
}
.ff-message-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 12px;
min-height: 16px;
}
.ff-message {
min-width: 0;
color: var(--ff-muted);
font-size: 0.6875rem;
line-height: 1.45;
transition: color 160ms var(--ff-ease);
}
.ff-message > span {
display: flex;
align-items: flex-start;
gap: 5px;
animation: ff-message-in 190ms var(--ff-ease) both;
}
.ff-message svg {
flex: none;
width: 13px;
height: 13px;
margin-top: 1px;
}
.ff-root[data-tone="error"] .ff-message {
color: var(--ff-error);
}
.ff-root[data-tone="success"] .ff-message {
color: var(--ff-ok);
}
.ff-count {
flex: none;
color: var(--ff-muted);
font-family: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
font-size: 0.625rem;
font-variant-numeric: tabular-nums;
line-height: 1.6;
}
@keyframes ff-message-in {
from {
opacity: 0;
transform: translateY(-2px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
@media (max-width: 480px) {
.ff-input {
font-size: 16px;
}
}
@media (prefers-reduced-motion: reduce) {
.ff-frame,
.ff-frame::after,
.ff-corner,
.ff-label,
.ff-message,
.ff-message > span {
transition-duration: 0.01ms;
animation-duration: 0.01ms;
}
}