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

clean up the temp textarea #196

Closed
DmitryEfimenko opened this issue Jun 24, 2019 · 3 comments · Fixed by #197
Closed

clean up the temp textarea #196

DmitryEfimenko opened this issue Jun 24, 2019 · 3 comments · Fixed by #197

Comments

@DmitryEfimenko
Copy link

Thanks for a useful library!
My use-case is quite unique, but nonetheless, here it is:

  • My website makes use of keyboard shortcuts. For example, pressing "/" will open a search bar input and put a focus on that input. The event handler that listens for the "/" ignores events if document.activeElement is an input or textarea.
  • Once the user found the element using this search feature, the user will click on it, which will copy something into the clipboard using this library.
  • Now, at this point, the user may press "/" again to search for another item and that's where the bug is. Pressing "/" does not open the search bar because after copying things into the clipboard activeElement becomes the temp textarea that this library generates here.

This issue can be easily solved if we destroy the textarea after using it.
I propose to replace line 81 with the following:

const toReturn = this.copyFromInputElement(this.tempTextArea);
this.destroy(this.tempTextArea.parentElement);
return toReturn;

I have tested this and it works for my use-case. Please let me know what you think.

@maxisam
Copy link
Owner

maxisam commented Jun 26, 2019

I understand. I wonder if you can create an option for this, like isDestoryTempEverytime. So if isDestoryTempEverytime is true, we remove the tempTextArea after copying. Therefore, for people who don't care about this, they don't need to create and destroy every time.

@DmitryEfimenko
Copy link
Author

The option for enabling/disabling this functionality sounds like a great idea! Another possible name for the option: cleanUpAfterCopy or destroyAfterCopy. I don't mind any name though - choose whatever you think is best.

Will you be doing the code change or would you like a PR?

@maxisam
Copy link
Owner

maxisam commented Jun 26, 2019

cleanUpAfterCopy sounds good to me. Welcome to make a PR. I am a bit busy now. Thx!

DmitryEfimenko pushed a commit to DmitryEfimenko/ngx-clipboard that referenced this issue Jun 26, 2019
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.

2 participants