Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(components): Add Copy Link button to Input component #7131

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

sumamakhan761
Copy link

@sumamakhan761 sumamakhan761 commented Apr 5, 2025

Closes #7130

Feature: Add "Copy Link" button to Input component

Description

This component adds a "Copy Link" button to the right of the input field. When clicked, it copies the input value to the user's clipboard using the Clipboard API.

Implementation

import { useRef } from "react"
export default function CopyLinkComponent() {
  const inputRef = useRef<HTMLInputElement>(null);

  const handleCopy = () => {
    if (inputRef.current) {
      navigator.clipboard.writeText(inputRef.current.value);
    }
  };

  return (
    <div className="flex space-x-2">
      <Input
        ref={inputRef}
        value="http://example.com/link/to/document"
        readOnly
      />
      <Button variant="secondary" className="shrink-0" onClick={handleCopy}>
        Copy Link
      </Button>
    </div>
  );
}

Copy link

vercel bot commented Apr 5, 2025

@sumamakhan7611 is attempting to deploy a commit to the shadcn-pro Team on Vercel.

A member of the Team first needs to authorize it.

@sumamakhan761
Copy link
Author

@shadcn @JoschuaSchneider please review my PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat]: Add copy-to-clipboard functionality to Input + Button link sharing component
2 participants