Dev Helpers
← Back

Read-only copy field

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

Open this example in the interactive library

Live preview

Source code

// components/ReadOnlyCopyField.tsx

import { useRef } from "react";

export default function ReadOnlyCopyField({
  label = "Display name",
  hint = "Visible to your team",
}: { label?: string; hint?: string } = {}) {
  const ref = useRef<HTMLInputElement>(null);
  return (
    <label>
      {label}
      <input ref={ref} readOnly value={hint} />
      <button
        type="button"
        onClick={() => {
          ref.current?.focus();
          ref.current?.select();
        }}
      >
        Select text
      </button>
    </label>
  );
}