Open this example in the interactive library
Live preview
Source code
// components/FocusFieldShortcut.tsx
import { useRef } from "react";
export default function FocusFieldShortcut({
label = "Display name",
}: { label?: string } = {}) {
const ref = useRef<HTMLInputElement>(null);
return (
<section>
<button onClick={() => ref.current?.focus()}>Edit {label}</button>
<label>
{label}
<input ref={ref} />
</label>
</section>
);
}
