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

Seemed wrong preventDefault? #131

Open
xiaomingTang opened this issue Apr 13, 2023 · 0 comments · May be fixed by #132
Open

Seemed wrong preventDefault? #131

xiaomingTang opened this issue Apr 13, 2023 · 0 comments · May be fixed by #132

Comments

@xiaomingTang
Copy link

https://github.com/sudodoki/copy-to-clipboard/blob/main/index.js#L69

If set options.onCopy, and NOT set options.format, copy will failed.

import copy from 'copy-to-clipboard'

copy('text', {
  // do NOT set format
  onCopy: () => {
    // onCopy callback will be triggered
    // but WONT copy correctly
  },
})

because:

mark.addEventListener('copy', function (e) {
  if (options.format) {
    // the preventDefault() is ok
    e.preventDefault()
    // do something...
    // re-set the clipboard data here
    clipboard.setData(options.format, text)
  }

  if (options.onCopy) {
    // the preventDefault() prevent the default copy behavior
    // it cause a bug
    // the preventDefault() should be removed.
    e.preventDefault()
    options.onCopy(e.clipboardData);
  }
})
xiaomingTang pushed a commit to xiaomingTang/copy-to-clipboard that referenced this issue Apr 14, 2023
@xiaomingTang xiaomingTang linked a pull request Apr 14, 2023 that will close this issue
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 a pull request may close this issue.

1 participant