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(useClipboard): support legacy copy #2336

Merged
merged 2 commits into from Oct 25, 2022
Merged

feat(useClipboard): support legacy copy #2336

merged 2 commits into from Oct 25, 2022

Conversation

lumdzeehol
Copy link
Contributor

Description

Add legacy: boolean option.
It will fallback to legacy methods document.execCommand('copy') if ClipboardApi is not allowed, for scenes like hosting website with IP adress, especially during development.
Relate to #1276

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Copy link
Member

@sxzz sxzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, I don't think this feature is necessary. document.execCommand is supported in all modern browsers. https://caniuse.com/document-execcommand
Also, it will cause a breaking change if isSupported is changed.

If Clipboard API is not supported, then you can handle fallback by yourself.

@sxzz sxzz requested a review from antfu October 19, 2022 08:57
@lumdzeehol
Copy link
Contributor Author

IMHO, I don't think this feature is necessary. document.execCommand is supported in all modern browsers. https://caniuse.com/document-execcommand Also, it will cause a breaking change if isSupported is changed.

If Clipboard API is not supported, then you can handle fallback by yourself.

I think you're right. useClipboard should just focus on clipboardApi.
but what if i want a compatible use function to handle copy? is it necessary to create a use like useCopy or sth ? for that execCommand needs lots of template code everytime i code it.😢

@sxzz
Copy link
Member

sxzz commented Oct 19, 2022

Yeah, I think it's a good idea, to combine Clipboard API and document.execCommand into one function called useCopy. WDYT @antfu

@antfu
Copy link
Member

antfu commented Oct 25, 2022

LGTM. Do you mind to send another PR to the document mention about this? Thanks

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.

None yet

3 participants