Dev Helpers
← Back

Focus field shortcut

Import and render <FocusFieldShortcut /> in a React project.

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>
  );
}